From c42cd8664719d31d429cb18d6f51fd7a3d841149 Mon Sep 17 00:00:00 2001 From: Igor Timofeev Date: Wed, 13 Feb 2019 11:47:45 +0300 Subject: [PATCH] Added GPU rebinding on destroying/placing screen block --- EFI/Full.lua | 3 +- EFI/Minified.lua | 2 +- Libraries/Screen.lua | 20 +++++++----- OS.lua | 74 +++++++++++++++++++++++++++++++------------- 4 files changed, 67 insertions(+), 32 deletions(-) diff --git a/EFI/Full.lua b/EFI/Full.lua index 1348d36d..06194a39 100644 --- a/EFI/Full.lua +++ b/EFI/Full.lua @@ -3,6 +3,8 @@ local stringsMain, stringsChangeLabel, stringKeyDown, stringsFilesystem, colorsT local eeprom, gpu, internetAddress = componentProxy(componentList("eeprom")()), componentProxy(componentList("gpu")()), componentList("internet")() +gpu.bind(componentList("screen")(), true) + local shutdown, gpuSet, gpuSetBackground, gpuSetForeground, gpuFill, eepromSetData, eepromGetData, screenWidth, screenHeight = computer.shutdown, gpu.set, gpu.setBackground, gpu.setForeground, gpu.fill, eeprom.setData, eeprom.getData, gpu.getResolution() local OSList, rectangle, centrizedText, menuElement = @@ -182,7 +184,6 @@ local boot, menuBack, menu, input = end end -gpu.bind(componentList("screen")(), true) status(stringsMain, "Hold Alt to show boot options") local deadline, eventData = uptime() + 1 diff --git a/EFI/Minified.lua b/EFI/Minified.lua index 59c1a37c..6e5c066c 100644 --- a/EFI/Minified.lua +++ b/EFI/Minified.lua @@ -1 +1 @@ -local a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r="MineOS EFI","Change label","key_down","filesystem",0x2D2D2D,0xE1E1E1,0x878787,0x878787,0xE1E1E1,component.proxy,component.list,computer.pullSignal,computer.uptime,table.insert,math.max,math.min,math.huge,math.floor;local s,t,u=j(k("eeprom")()),j(k("gpu")()),k("internet")()local v,w,x,y,z,A,B,C,D=computer.shutdown,t.set,t.setBackground,t.setForeground,t.fill,s.setData,s.getData,t.getResolution()local E,F,G,H={{"/OS.lua",function()end},{"/init.lua",function()computer.getBootAddress,computer.setBootAddress=B,A end}},function(I,J,K,L,M)x(M)z(I,J,K,L," ")end,function(J,N,O)local I=r(C/2-#O/2)y(N)w(I,J,O)end,function(O,P,Q)return{s=O,c=P,b=Q}end;local function R(J,S)J=r(D/2-J/2)F(1,1,C,D,f)G(J,e,S)return J+2 end;local function T(S,U,V)local W={}for X in U:gmatch("[^\r\n]+")do W[#W+1]=X:gsub("\t"," ")end;local J=R(#W,S)for Y=1,#W do G(J,g,W[Y])J=J+1 end;if V then repeat V=l()until V==c or V=="touch"end end;local function Z(...)local _,a0=load(...)if _ then _,a0=xpcall(_,debug.traceback)if _ then return end end;T(a,a0,1)end;local a1,a2,a3,a4=function(a5)for Y=1,#E do if a5.exists(E[Y][1])then T(a,"Booting from "..(a5.getLabel()or a5.address))if B()~=a5.address then A(a5.address)end;E[Y][2]()local a6,a7,a8,a9,a0=a5.open(E[Y][1],"rb"),""repeat a8=a5.read(a6,q)a7=a7 ..(a8 or"")until not a8;a5.close(a6)Z(a7,"="..E[Y][1])return 1 end end end,function(aa)return H("Back",aa,1)end,function(S,ab)local ac,ad=1,0;for Y=1,#ab do ad=math.max(ad,#ab[Y].s)end;while 1 do local J,I,ae=R(#ab+2,S)for Y=1,#ab do I=r(C/2-#ab[Y].s/2)if Y==ac then F(r(C/2-ad/2)-2,J,ad+4,1,h)y(i)w(I,J,ab[Y].s)x(f)else y(g)w(I,J,ab[Y].s)end;J=J+1 end;ae={l()}if ae[1]==c then if ae[4]==200 and ac>1 then ac=ac-1 elseif ae[4]==208 and ac<#ab then ac=ac+1 elseif ae[4]==28 then if ab[ac].c then ab[ac].c()end;if ab[ac].b then return end end end end end,function(J,af)local O,ag,ah,ae,ai="",true;while 1 do ah=af..O;z(1,J,C,1," ")y(g)w(r(C/2-#ah/2),J,ah..(ag and"█"or""))ae={l(0.5)}if ae[1]==c then if ae[4]==28 then return O elseif ae[4]==14 then O=O:sub(1,-2)else ai=unicode.char(ae[3])if ai:match("^[%w%d%p%s]+")then O=O..ai end end;ag=true elseif ae[1]=="clipboard"then O=O..ae[3]elseif not ae[1]then ag=not ag end end end;t.bind(k("screen")(),true)T(a,"Hold Alt to show boot options")local aj,ae=m()+1;while m() "or" ")..al(ar,12)..al(a5.spaceTotal()>1048576 and"HDD"or a5.spaceTotal()>65536 and"FDD"or"SYS",3)..al(as and"R"or"R/W",3)..al(string.format("%.1f",a5.spaceUsed()/a5.spaceTotal()*100).."%",6)..aq:sub(1,7).."…",function()a3(ar.." ("..aq..")",an)end))end end;ap()a3("Select filesystem",am)end),H("Shutdown",function()v()end),a2()}if u then n(ak,2,H("Internet recovery",function()local a6,a7,_,a0=j(u).request("https://raw.githubusercontent.com/IgorTimofeev/MineOS/master/Installer/Main.lua"),""if a6 then T(a,"Downloading recovery script")while 1 do _,a0=a6.read(q)if _ then a7=a7 .._ else a6.close()if a0 then T(a,a0,1)else Z(a7,"=string")end;break end end else T(a,"invalid URL-address",1)end end))end;a3(a,ak)end end;local a5=j(B())if not(a5 and a1(a5))then for aq in k(d)do a5=j(aq)if a1(a5)then break else a5=nil end end;if not a5 then T(a,"No bootable mediums found",1)end end;v() \ No newline at end of file +local a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r="MineOS EFI","Change label","key_down","filesystem",0x2D2D2D,0xE1E1E1,0x878787,0x878787,0xE1E1E1,component.proxy,component.list,computer.pullSignal,computer.uptime,table.insert,math.max,math.min,math.huge,math.floor;local s,t,u=j(k("eeprom")()),j(k("gpu")()),k("internet")()t.bind(k("screen")(),true)local v,w,x,y,z,A,B,C,D=computer.shutdown,t.set,t.setBackground,t.setForeground,t.fill,s.setData,s.getData,t.getResolution()local E,F,G,H={{"/OS.lua",function()end},{"/init.lua",function()computer.getBootAddress,computer.setBootAddress=B,A end}},function(I,J,K,L,M)x(M)z(I,J,K,L," ")end,function(J,N,O)local I=r(C/2-#O/2)y(N)w(I,J,O)end,function(O,P,Q)return{s=O,c=P,b=Q}end;local function R(J,S)J=r(D/2-J/2)F(1,1,C,D,f)G(J,e,S)return J+2 end;local function T(S,U,V)local W={}for X in U:gmatch("[^\r\n]+")do W[#W+1]=X:gsub("\t"," ")end;local J=R(#W,S)for Y=1,#W do G(J,g,W[Y])J=J+1 end;if V then repeat V=l()until V==c or V=="touch"end end;local function Z(...)local _,a0=load(...)if _ then _,a0=xpcall(_,debug.traceback)if _ then return end end;T(a,a0,1)end;local a1,a2,a3,a4=function(a5)for Y=1,#E do if a5.exists(E[Y][1])then T(a,"Booting from "..(a5.getLabel()or a5.address))if B()~=a5.address then A(a5.address)end;E[Y][2]()local a6,a7,a8,a9,a0=a5.open(E[Y][1],"rb"),""repeat a8=a5.read(a6,q)a7=a7 ..(a8 or"")until not a8;a5.close(a6)Z(a7,"="..E[Y][1])return 1 end end end,function(aa)return H("Back",aa,1)end,function(S,ab)local ac,ad=1,0;for Y=1,#ab do ad=math.max(ad,#ab[Y].s)end;while 1 do local J,I,ae=R(#ab+2,S)for Y=1,#ab do I=r(C/2-#ab[Y].s/2)if Y==ac then F(r(C/2-ad/2)-2,J,ad+4,1,h)y(i)w(I,J,ab[Y].s)x(f)else y(g)w(I,J,ab[Y].s)end;J=J+1 end;ae={l()}if ae[1]==c then if ae[4]==200 and ac>1 then ac=ac-1 elseif ae[4]==208 and ac<#ab then ac=ac+1 elseif ae[4]==28 then if ab[ac].c then ab[ac].c()end;if ab[ac].b then return end end end end end,function(J,af)local O,ag,ah,ae,ai="",true;while 1 do ah=af..O;z(1,J,C,1," ")y(g)w(r(C/2-#ah/2),J,ah..(ag and"█"or""))ae={l(0.5)}if ae[1]==c then if ae[4]==28 then return O elseif ae[4]==14 then O=O:sub(1,-2)else ai=unicode.char(ae[3])if ai:match("^[%w%d%p%s]+")then O=O..ai end end;ag=true elseif ae[1]=="clipboard"then O=O..ae[3]elseif not ae[1]then ag=not ag end end end;T(a,"Hold Alt to show boot options")local aj,ae=m()+1;while m() "or" ")..al(ar,12)..al(a5.spaceTotal()>1048576 and"HDD"or a5.spaceTotal()>65536 and"FDD"or"SYS",3)..al(as and"R"or"R/W",3)..al(string.format("%.1f",a5.spaceUsed()/a5.spaceTotal()*100).."%",6)..aq:sub(1,7).."…",function()a3(ar.." ("..aq..")",an)end))end end;ap()a3("Select filesystem",am)end),H("Shutdown",function()v()end),a2()}if u then n(ak,2,H("Internet recovery",function()local a6,a7,_,a0=j(u).request("https://raw.githubusercontent.com/IgorTimofeev/MineOS/master/Installer/Main.lua"),""if a6 then T(a,"Downloading recovery script")while 1 do _,a0=a6.read(q)if _ then a7=a7 .._ else a6.close()if a0 then T(a,a0,1)else Z(a7,"=string")end;break end end else T(a,"invalid URL-address",1)end end))end;a3(a,ak)end end;local a5=j(B())if not(a5 and a1(a5))then for aq in k(d)do a5=j(aq)if a1(a5)then break else a5=nil end end;if not a5 then T(a,"No bootable mediums found",1)end end;v() \ No newline at end of file diff --git a/Libraries/Screen.lua b/Libraries/Screen.lua index 3d6ca0b5..d164dc9c 100755 --- a/Libraries/Screen.lua +++ b/Libraries/Screen.lua @@ -84,9 +84,17 @@ local function getHeight() return bufferHeight end -local function bind(...) - GPUProxy.bind(...) - flush(GPUProxyGetResolution()) +local function bind(address, reset) + local success, reason = GPUProxy.bind(address, reset) + if success then + if reset then + setResolution(GPUProxy.maxResolution()) + else + setResolution(bufferWidth, bufferHeight) + end + else + return success, reason + end end local function getGPUProxy() @@ -110,7 +118,7 @@ end local function setGPUProxy(proxy) GPUProxy = proxy updateGPUProxyMethods() - flush(GPUProxyGetResolution()) + flush() end local function getScaledResolution(scale) @@ -582,10 +590,6 @@ end -------------------------------------------------------------------------------- -setGPUProxy(component.proxy(component.list("gpu")())) - --------------------------------------------------------------------------------- - return { getCoordinates = getCoordinates, getIndex = getIndex, diff --git a/OS.lua b/OS.lua index 201b0f0a..914ebb44 100644 --- a/OS.lua +++ b/OS.lua @@ -130,7 +130,7 @@ local paths = UIRequire("Paths") local event = UIRequire("Event") local filesystem = UIRequire("Filesystem") --- Setting main filesystem proxy too what are we booting from +-- Setting main filesystem proxy to what are we booting from filesystem.setProxy(bootFilesystemProxy) -- Redeclaring requireExists function after filesystem library initialization @@ -145,7 +145,11 @@ UIRequire("Color") UIRequire("Text") UIRequire("Number") local image = UIRequire("Image") -UIRequire("Screen") +local screen = UIRequire("Screen") + +-- Setting currently chosen GPU component as screen buffer main one +screen.setGPUProxy(GPUProxy) + local GUI = UIRequire("GUI") local system = UIRequire("System") UIRequire("Network") @@ -158,29 +162,55 @@ package.loaded.unicode = unicode ---------------------------------------- Main loop ---------------------------------------- --- "double_touch" event handler -local doubleTouchInterval, doubleTouchX, doubleTouchY, doubleTouchButton, doubleTouchUptime, doubleTouchScreenAddress = 0.3 -if not event.doubleTouchHandler then - event.doubleTouchHandler = event.addHandler( - function(signalType, screenProxyAddress, x, y, button, user) - if signalType == "touch" then - local uptime = computer.uptime() - - if doubleTouchX == x and doubleTouchY == y and doubleTouchButton == button and doubleTouchScreenAddress == screenProxyAddress and uptime - doubleTouchUptime <= doubleTouchInterval then - computer.pushSignal("double_touch", screenProxyAddress, x, y, button, user) - event.skip("touch") - end - - doubleTouchX, doubleTouchY, doubleTouchButton, doubleTouchUptime, doubleTouchScreenAddress = x, y, button, uptime, screenProxyAddress - end - end - ) -end - --- Creating main OS workspace, which contains every window/menu/etc. +-- Creating OS workspace, which contains every window/menu/etc. local workspace = GUI.workspace() system.setWorkspace(workspace) +-- "double_touch" event handler +local doubleTouchInterval, doubleTouchX, doubleTouchY, doubleTouchButton, doubleTouchUptime, doubleTouchcomponentAddress = 0.3 +event.addHandler( + function(signalType, componentAddress, x, y, button, user) + if signalType == "touch" then + local uptime = computer.uptime() + + if doubleTouchX == x and doubleTouchY == y and doubleTouchButton == button and doubleTouchcomponentAddress == componentAddress and uptime - doubleTouchUptime <= doubleTouchInterval then + computer.pushSignal("double_touch", componentAddress, x, y, button, user) + event.skip("touch") + end + + doubleTouchX, doubleTouchY, doubleTouchButton, doubleTouchUptime, doubleTouchcomponentAddress = x, y, button, uptime, componentAddress + end + end +) + +-- Screen component attaching/detaching event handler +event.addHandler( + function(signalType, componentAddress, componentType) + if (signalType == "component_added" or signalType == "component_removed") and componentType == "screen" then + local gpu = screen.getGPUProxy() + + local function bindScreen(address) + screen.bind(address, false) + gpu.setDepth(gpu.maxDepth()) + workspace:draw() + end + + if signalType == "component_added" then + if not gpu.getScreen() then + bindScreen(componentAddress) + end + else + if not gpu.getScreen() then + local address = component.list("screen")() + if address then + bindScreen(address) + end + end + end + end + end +) + -- Logging in system.authorize()