titlebar/close/moving of nwm windows
This commit is contained in:
@@ -6,12 +6,16 @@ local peripheral = _G.peripheral
|
|||||||
local term = _G.term
|
local term = _G.term
|
||||||
|
|
||||||
local args = { ... }
|
local args = { ... }
|
||||||
local mon = args[1] and device[args[1]] or peripheral.wrap(args[1]) or
|
local mon = not args[1] and term.current() or
|
||||||
|
device[args[1]] or
|
||||||
|
peripheral.wrap(args[1]) or
|
||||||
peripheral.find('monitor') or
|
peripheral.find('monitor') or
|
||||||
error('Syntax: debug <monitor>')
|
error('Syntax: debug <monitor>')
|
||||||
|
|
||||||
mon.clear()
|
mon.clear()
|
||||||
mon.setTextScale(.5)
|
if mon.setTextScale then
|
||||||
|
mon.setTextScale(.5)
|
||||||
|
end
|
||||||
mon.setCursorPos(1, 1)
|
mon.setCursorPos(1, 1)
|
||||||
|
|
||||||
local oldDebug = _G._syslog
|
local oldDebug = _G._syslog
|
||||||
@@ -26,7 +30,9 @@ repeat
|
|||||||
local e, side = os.pullEventRaw('monitor_touch')
|
local e, side = os.pullEventRaw('monitor_touch')
|
||||||
if e == 'monitor_touch' and side == mon.side then
|
if e == 'monitor_touch' and side == mon.side then
|
||||||
mon.clear()
|
mon.clear()
|
||||||
mon.setTextScale(.5)
|
if mon.setTextScale then
|
||||||
|
mon.setTextScale(.5)
|
||||||
|
end
|
||||||
mon.setCursorPos(1, 1)
|
mon.setCursorPos(1, 1)
|
||||||
end
|
end
|
||||||
until e == 'terminate'
|
until e == 'terminate'
|
||||||
|
|||||||
@@ -202,7 +202,6 @@ local page = UI.Page {
|
|||||||
label = 'Find',
|
label = 'Find',
|
||||||
search = UI.TextEntry {
|
search = UI.TextEntry {
|
||||||
x = 7, ex = -3,
|
x = 7, ex = -3,
|
||||||
limit = 512,
|
|
||||||
accelerators = {
|
accelerators = {
|
||||||
[ 'enter' ] = 'accept',
|
[ 'enter' ] = 'accept',
|
||||||
},
|
},
|
||||||
@@ -232,7 +231,6 @@ local page = UI.Page {
|
|||||||
label = 'Save',
|
label = 'Save',
|
||||||
filename = UI.TextEntry {
|
filename = UI.TextEntry {
|
||||||
x = 7, ex = -3,
|
x = 7, ex = -3,
|
||||||
limit = 512,
|
|
||||||
accelerators = {
|
accelerators = {
|
||||||
[ 'enter' ] = 'accept',
|
[ 'enter' ] = 'accept',
|
||||||
},
|
},
|
||||||
@@ -339,7 +337,6 @@ local page = UI.Page {
|
|||||||
quick_open = UI.SlideOut {
|
quick_open = UI.SlideOut {
|
||||||
filter_entry = UI.TextEntry {
|
filter_entry = UI.TextEntry {
|
||||||
x = 2, y = 2, ex = -2,
|
x = 2, y = 2, ex = -2,
|
||||||
limit = 256,
|
|
||||||
shadowText = 'File name',
|
shadowText = 'File name',
|
||||||
accelerators = {
|
accelerators = {
|
||||||
[ 'enter' ] = 'accept',
|
[ 'enter' ] = 'accept',
|
||||||
|
|||||||
@@ -29,7 +29,6 @@ local tab = UI.Tab {
|
|||||||
},
|
},
|
||||||
entry = UI.TextEntry {
|
entry = UI.TextEntry {
|
||||||
x = 3, y = 5 , ex = -3,
|
x = 3, y = 5 , ex = -3,
|
||||||
limit = 256,
|
|
||||||
shadowText = 'enter new path',
|
shadowText = 'enter new path',
|
||||||
accelerators = {
|
accelerators = {
|
||||||
enter = 'add_path',
|
enter = 'add_path',
|
||||||
|
|||||||
@@ -5,7 +5,6 @@
|
|||||||
local Terminal = require('opus.terminal')
|
local Terminal = require('opus.terminal')
|
||||||
local Util = require('opus.util')
|
local Util = require('opus.util')
|
||||||
|
|
||||||
local colors = _G.colors
|
|
||||||
local device = _G.device
|
local device = _G.device
|
||||||
|
|
||||||
local Glasses = { }
|
local Glasses = { }
|
||||||
@@ -102,6 +101,13 @@ function Glasses.create(args)
|
|||||||
function gterm.getTextScale()
|
function gterm.getTextScale()
|
||||||
return opts.scale
|
return opts.scale
|
||||||
end
|
end
|
||||||
|
function gterm.move(x, y)
|
||||||
|
if opts.x ~= x or opts.y ~= y then
|
||||||
|
opts.x, opts.y = x, y
|
||||||
|
pos = { x = opts.x * xs, y = opts.y * ys }
|
||||||
|
group.setPosition(pos.x, pos.y)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
gterm.name = opts.name
|
gterm.name = opts.name
|
||||||
gterm.side = opts.name
|
gterm.side = opts.name
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ local fsm = machine.create({
|
|||||||
|
|
||||||
-- state changes
|
-- state changes
|
||||||
onenterwait = function()
|
onenterwait = function()
|
||||||
print('waitng for fishing rod to be selected')
|
print('waiting for fishing rod to be selected')
|
||||||
if icon then
|
if icon then
|
||||||
icon.remove()
|
icon.remove()
|
||||||
icon = canvas.addItem({ w - 20, h - 20 }, 'minecraft:fishing_rod' )
|
icon = canvas.addItem({ w - 20, h - 20 }, 'minecraft:fishing_rod' )
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
--[[
|
--[[
|
||||||
A simplistic window manager for glasses.
|
A simplistic window manager for glasses.
|
||||||
TODO: support moving windows via mouse drag.
|
|
||||||
|
TODO:
|
||||||
|
opacity for text/background separately
|
||||||
|
support for specifying scale factor
|
||||||
]]
|
]]
|
||||||
|
|
||||||
local Config = require('opus.config')
|
local Config = require('opus.config')
|
||||||
@@ -8,15 +11,17 @@ local Glasses = require('neural.glasses')
|
|||||||
local UI = require('opus.ui')
|
local UI = require('opus.ui')
|
||||||
local Util = require('opus.util')
|
local Util = require('opus.util')
|
||||||
|
|
||||||
|
local fs = _G.fs
|
||||||
local kernel = _G.kernel
|
local kernel = _G.kernel
|
||||||
local multishell = _ENV.multishell
|
local multishell = _ENV.multishell
|
||||||
local shell = _ENV.shell
|
local shell = _ENV.shell
|
||||||
|
|
||||||
local config = Config.load('nwm', { session = { } })
|
local config = Config.load('nwm', { session = { } })
|
||||||
|
|
||||||
-- TODO: figure out how to better define scaling
|
-- TODO: figure out how to better support scaling
|
||||||
local scale = .5
|
local scale = .5
|
||||||
local xs, ys = 6 * scale, 9 * scale
|
local xs, ys = 6 * scale, 9 * scale
|
||||||
|
local dragging
|
||||||
|
|
||||||
local events = {
|
local events = {
|
||||||
glasses_click = 'mouse_click',
|
glasses_click = 'mouse_click',
|
||||||
@@ -31,16 +36,39 @@ local function hook(e, eventData)
|
|||||||
local y = math.floor(eventData[3] / ys)
|
local y = math.floor(eventData[3] / ys)
|
||||||
local clickedTab
|
local clickedTab
|
||||||
|
|
||||||
|
if dragging then
|
||||||
|
if e == 'glasses_up' then
|
||||||
|
dragging = nil
|
||||||
|
elseif e == 'glasses_drag' then
|
||||||
|
local dx = x - dragging.ax
|
||||||
|
local dy = y - dragging.ay
|
||||||
|
dragging.tab.window.move(dragging.wx + dx, dragging.wy + dy)
|
||||||
|
dragging.tab.titleBar.move(dragging.wx + dx, dragging.wy + dy - 1)
|
||||||
|
|
||||||
|
dragging.tab.wmargs.x = dragging.wx + dx
|
||||||
|
dragging.tab.wmargs.y = dragging.wy + dy
|
||||||
|
Config.update('nwm', config)
|
||||||
|
end
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
for _,tab in ipairs(kernel.routines) do
|
for _,tab in ipairs(kernel.routines) do
|
||||||
if tab.window.type == 'glasses' then
|
if tab.window.type == 'glasses' then
|
||||||
local wx, wy = tab.window.getPosition()
|
local wx, wy = tab.window.getPosition()
|
||||||
local ww, wh = tab.window.getSize()
|
local ww, wh = tab.window.getSize()
|
||||||
|
|
||||||
if x >= wx and x <= wx + ww and y >= wy and y <= wy + wh then
|
if x >= wx and x <= wx + ww and y > wy and y < wy + wh then
|
||||||
clickedTab = tab
|
clickedTab = tab
|
||||||
x = x - wx
|
x = x - wx
|
||||||
y = y - wy
|
y = y - wy
|
||||||
break
|
break
|
||||||
|
elseif e == 'glasses_click' and x >= wx and x <= wx + ww and y == wy then
|
||||||
|
if x == wx + ww - 1 then
|
||||||
|
multishell.terminate(tab.uid)
|
||||||
|
else
|
||||||
|
dragging = { tab = tab, ax = x, ay = y, wx = wx, wy = wy }
|
||||||
|
end
|
||||||
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -65,6 +93,18 @@ kernel.hook(hookEvents, hook)
|
|||||||
local function run(args)
|
local function run(args)
|
||||||
local window = Glasses.create(args)
|
local window = Glasses.create(args)
|
||||||
|
|
||||||
|
local titleBar = Glasses.create({
|
||||||
|
x = args.x,
|
||||||
|
y = args.y - 1,
|
||||||
|
height = 1,
|
||||||
|
width = args.width,
|
||||||
|
opacity = args.opacity,
|
||||||
|
})
|
||||||
|
titleBar.canvas:clear('yellow')
|
||||||
|
titleBar.canvas:write(1, 1, ' ' .. fs.getName(args.path), nil, 'black')
|
||||||
|
titleBar.canvas:write(args.width - 2, 1, ' x ', nil, 'black')
|
||||||
|
titleBar.redraw()
|
||||||
|
|
||||||
multishell.openTab({
|
multishell.openTab({
|
||||||
path = args.path,
|
path = args.path,
|
||||||
args = args.args,
|
args = args.args,
|
||||||
@@ -73,8 +113,11 @@ local function run(args)
|
|||||||
Util.removeByValue(config.session, args)
|
Util.removeByValue(config.session, args)
|
||||||
Config.update('nwm', config)
|
Config.update('nwm', config)
|
||||||
window.destroy()
|
window.destroy()
|
||||||
|
titleBar.destroy()
|
||||||
end,
|
end,
|
||||||
window = window,
|
window = window,
|
||||||
|
titleBar = titleBar,
|
||||||
|
wmargs = args,
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -90,6 +133,8 @@ UI:setPage(UI.Page {
|
|||||||
UI.Slider {
|
UI.Slider {
|
||||||
min = 0, max = 255,
|
min = 0, max = 255,
|
||||||
formLabel = 'Opacity', formKey = 'opacity', formIndex = 3,
|
formLabel = 'Opacity', formKey = 'opacity', formIndex = 3,
|
||||||
|
labelWidth = 3,
|
||||||
|
transform = math.floor,
|
||||||
},
|
},
|
||||||
UI.Text {
|
UI.Text {
|
||||||
x = 10, y = 5,
|
x = 10, y = 5,
|
||||||
@@ -137,6 +182,9 @@ UI:setPage(UI.Page {
|
|||||||
run(opts)
|
run(opts)
|
||||||
self.notification:success('Started program')
|
self.notification:success('Started program')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
elseif event.type == 'form_cancel' then
|
||||||
|
UI:quit()
|
||||||
end
|
end
|
||||||
return UI.Page.eventHandler(self, event)
|
return UI.Page.eventHandler(self, event)
|
||||||
end,
|
end,
|
||||||
|
|||||||
Reference in New Issue
Block a user