-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathflattop
More file actions
161 lines (152 loc) · 5.27 KB
/
Copy pathflattop
File metadata and controls
161 lines (152 loc) · 5.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
local themes = {
standard = {
titlebar = {"=", "0", "f"},
ostext = {" ", "0", "f"},
tasktext = {" ", "0", "f"},
tasksep = {"|", "0", "f"},
},
pretty = {
titlebar = {" ", "0", "8"},
ostext = {" ", "b", "8"},
tasktext = {" ", "f", "8"},
tasksep = {"|", "f", "8"},
}
}
if fs.exists("/LyqydOS/themes/desktop") and fs.isDir("/LyqydOS/themes/desktop") then
for _, name in pairs(fs.list("/LyqydOS/themes/desktop")) do
local file = fs.combine("/LyqydOS/themes/desktop", name)
local env = {}
local fn, err = loadfile(file)
if fn then
setfenv(fn, env)
fn()
--copy into desktop themes
themes[name] = {}
for k, v in pairs(env) do
themes[name][k] = v
end
end
end
end
local deskID = process.id()
local deskRedirect = process.compositor:newBuffer(deskID)
deskRedirect.setBounds(1, process.compositor.y, process.compositor.x, process.compositor.y)
local x, y = deskRedirect.getSize()
--new term, previous term, next term keys.
process.addHook({"key", 59})
process.addHook({"key", 61})
process.addHook({"key", 62})
process.addHook({"redraw"})
local terms = {}
local focusTerm = nil
local function removeTerm(win)
process.compositor:removeBuffer(win.target.buffer)
for i = 1, #terms do
if terms[i].windows[1] == win then
table.remove(terms, i)
focusTerm = terms[i - 1] or terms[1]
break
end
end
end
local function addTerm()
local redirect = framebuffer.new(process.compositor.x, process.compositor.y - 1, process.compositor.target.isColor())
redirect.buffer.minX = 1
redirect.buffer.maxX = process.compositor.x
redirect.buffer.minY = 1
redirect.buffer.maxY = process.compositor.y - 1
table.insert(process.compositor.bufferStack, redirect.buffer)
local win = {redirect = redirect, target = redirect, destroy = function(self) removeTerm(self) end, caption = "lsh", setCaption = function(self, cap) self.caption = cap end}
local proc = process.new(function() shell.run("/LyqydOS/lsh") end, "lsh", win, redirect)
redirect.buffer.pid = #process.list
table.insert(terms, proc)
process.focus = proc.id
focusTerm = proc
end
local theme = themes[LyqydOS.desktop.theme]
addTerm()
while true do
event = {os.pullEvent()}
if event[1] == "key" and event[2] == 59 then
--add process
addTerm()
elseif event[1] == "key" and event[2] == 61 then
for i = 1, #terms do
if terms[i] == focusTerm then
if terms[i - 1] then
focusTerm = terms[i - 1]
elseif i == 1 then
focusTerm = terms[#terms]
end
process.focus = focusTerm.id
focusTerm:toFront()
break
end
end
elseif event[1] == "key" and event[2] == 62 then
for i = 1, #terms do
if terms[i] == focusTerm then
if terms[i + 1] then
focusTerm = terms[i + 1]
elseif i == #terms then
focusTerm = terms[1]
end
process.focus = focusTerm.id
focusTerm:toFront()
break
end
end
elseif event[1] == "set_property" then
if event[2] == "theme" then
if themes[event[3]] then
theme = themes[event[3]]
os.queueEvent("property_changed", process.id(), unpack(event))
else
os.queueEvent("property_refused", process.id(), unpack(event))
end
end
elseif event[1] == "redraw" then
titlebarItems = {}
for i=1, #process.list do
if process.list[i] and #process.list[i].windows >= 1 then
local proc = process.list[i]
table.insert(titlebarItems, {pID = i, text = proc.windows[#proc.windows].caption})
end
end
local taskText = {}
tasksClickable = 0
local usableWidth = x - 10
for eNum, eInfo in ipairs(titlebarItems) do
if #taskText * 9 + 9 > usableWidth then
if #taskText > 0 then
table.remove(taskText)
table.insert(taskText, "More... ")
--taskText = string.sub(taskText, 1, -10).."More... |"
end
break
end
local str = string.sub(eInfo.text, 1, 8)
str = str..string.rep(" ", 8 - #str)
--if taskText == "" then taskText = "|" end
table.insert(taskText, str)
--taskText = taskText..str.."|"
tasksClickable = tasksClickable + 1
end
deskRedirect.buffer.text[y] = theme.titlebar[1].."LyqydOS"..theme.titlebar[1]
deskRedirect.buffer.textColor[y] = theme.titlebar[2]..string.rep(theme.ostext[2], 7)..theme.titlebar[2]
deskRedirect.buffer.backColor[y] = theme.titlebar[3]..string.rep(theme.ostext[3], 7)..theme.titlebar[3]
if #taskText > 0 then
deskRedirect.buffer.text[y] = deskRedirect.buffer.text[y]..theme.tasksep[1]
deskRedirect.buffer.textColor[y] = deskRedirect.buffer.textColor[y]..theme.tasksep[2]
deskRedirect.buffer.backColor[y] = deskRedirect.buffer.backColor[y]..theme.tasksep[3]
for i = 1, #taskText do
deskRedirect.buffer.text[y] = deskRedirect.buffer.text[y]..taskText[i]..theme.tasksep[1]
deskRedirect.buffer.textColor[y] = deskRedirect.buffer.textColor[y]..string.rep(theme.tasktext[2], #taskText[i])..theme.tasksep[2]
deskRedirect.buffer.backColor[y] = deskRedirect.buffer.backColor[y]..string.rep(theme.tasktext[3], #taskText[i])..theme.tasksep[3]
end
end
deskRedirect.buffer.text[y] = deskRedirect.buffer.text[y]..string.rep(theme.titlebar[1], x - #deskRedirect.buffer.text[y])
deskRedirect.buffer.textColor[y] = deskRedirect.buffer.textColor[y]..string.rep(theme.titlebar[2], x - #deskRedirect.buffer.textColor[y])
deskRedirect.buffer.backColor[y] = deskRedirect.buffer.backColor[y]..string.rep(theme.titlebar[3], x - #deskRedirect.buffer.backColor[y])
end
end