-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApplet_windowlist.cc
More file actions
114 lines (87 loc) · 4.42 KB
/
Applet_windowlist.cc
File metadata and controls
114 lines (87 loc) · 4.42 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
#define PANEL_APPLET
#include "./Applet.h"
#include "./utils/wlr_windowlist.cc"
WindowList list;
const std::map<std::string, void(*)(std::string)> Applet::commands () {
return {};
}
const std::map<std::string,std::string> Applet::settings_default () {
return { {"mode","icon state"}, {"icon_path","/usr/share/icons/hicolor/{scalable,48x48,32x32}/apps/"}, {"icon_default",""}, {"text_source","name"}, {"progress_whitelist",""}, {"progress_blacklist",""} };
}
void Applet::load() {
list.init();
window->html_element( "#"+settings["ID"], "innerHTML", "`<style>#"+settings["ID"]+"{display: flex;} #"+settings["ID"]+" > div{color: white; margin: auto 3px; height: 100%; display: flex; align-items: center; background-size:50%; background-repeat:no-repeat; background-position:center; min-width:60px;} #"+settings["ID"]+" > div:hover{color: red;}</style>`" );
// TODO: vertical-compatible layout (use same code as panel)
window->call_js("\
['click', 'dragenter'].forEach(n => document.querySelector('#"+settings["ID"]+"').addEventListener(n, function(e) {\
(" + window->call_native([](std::vector<std::string> argsv) -> void {
void* ptr = reinterpret_cast<void*>(std::stoull(argsv[0]));
if (!list.windowlist.contains(ptr)) return;
auto& w = list.windowlist[ptr];
if (argsv[1] == "click"){
if (w.activated and !w.minimized) {
zwlr_foreign_toplevel_handle_v1_set_minimized((zwlr_foreign_toplevel_handle_v1*)w.handle);
}
else {
zwlr_foreign_toplevel_handle_v1_unset_minimized((zwlr_foreign_toplevel_handle_v1*)w.handle); // doesnt work when the window is already unminimized but behind another window
zwlr_foreign_toplevel_handle_v1_activate((zwlr_foreign_toplevel_handle_v1*)w.handle, /*global from header*/ seat);
}
}
else if (argsv[1] == "dragenter"){
zwlr_foreign_toplevel_handle_v1_unset_minimized((zwlr_foreign_toplevel_handle_v1*)w.handle); // doesnt work when the window is already unminimized but behind another window
zwlr_foreign_toplevel_handle_v1_activate((zwlr_foreign_toplevel_handle_v1*)w.handle, /*global from header*/ seat);
}
wl_display_roundtrip(list.display);
}) + ") (e.target.closest('#"+settings["ID"]+" > div').id.substr(2), e.type) })); \
");
}
void Applet::reload () {
}
void Applet::unload () {
list.clear();
// TODO
}
std::time_t Applet::update () {
list.handle();
for (auto& [k,w] : list.windowlist){
if (w.created) {
w.created = false;
window->html_element( "#"+settings["ID"]+" div#w-"+std::to_string(reinterpret_cast<uintptr_t>(w.handle)) ); // TODO: does this work correctly? - todo fix invalid selector when > (HUI)
if (settings["mode"].find("icon") != -1) {
// TODO: apply lookup path, fallback icon (in case none set, construct custom svg from app_id)
window->html_element( "#"+settings["ID"]+" div#w-"+std::to_string(reinterpret_cast<uintptr_t>(w.handle)), "style.backgroundImage", "`url(\""+get_xdg_icon(w.app_id,settings["icon_path"],settings["icon_default"])+"\")`");
}
}
else if (w.changed) {
w.changed = false;
if (settings["mode"].find("text") != -1) {
std::string text;
if (settings["text_source"] == "name") {
size_t pos = w.title.rfind(' ');
if (pos != -1) text = w.title.substr(pos);
else if (w.title.length() >= 2 /*and w.title.length() <= 20*/) text = w.title.substr(0,20);
else text = "Untitled";
}
else if (settings["text_source"] == "title") {
text = w.title;
}
else if (settings["text_source"] == "app_id") {
text = w.app_id;
}
window->html_element( "#"+settings["ID"]+" > div#w-"+std::to_string(reinterpret_cast<uintptr_t>(w.handle)), "innerHTML", "`"+text+"`" ); // TODO: sanitize text
}
if (settings["mode"].find("state") != -1) {
if (w.activated) window->html_element( "#"+settings["ID"]+" div#w-"+std::to_string(reinterpret_cast<uintptr_t>(w.handle)), "style.backgroundColor", "'rgba(255,255,255,0.15)'");
else window->html_element( "#"+settings["ID"]+" div#w-"+std::to_string(reinterpret_cast<uintptr_t>(w.handle)), "style.backgroundColor", "''");
}
if (settings["mode"].find("progress") != -1) {
// TODO: parse progress from app titles
}
}
else if (w.closed) {
w.closed = false;
window->html_element( "#"+settings["ID"]+" > div#w-"+std::to_string(reinterpret_cast<uintptr_t>(w.handle)), "remove()" ); // TODO: suboptimal cos attempts return
}
}
return std::time(nullptr)+1;
}