aboutsummaryrefslogtreecommitdiff
path: root/.config/awesome/ui/window_switcher/init.lua
blob: f14c8651cb73f9ee1a90b3487dd7144f8d7f3c85 (plain)
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
162
163
164
165
166
167
168
169
170
171
172
local awful = require "awful"
local vars = require "misc.vars"
local wibox = require "wibox"
local obj = require "gears.object"
local debug = require "gears.debug"
local naughty = require "naughty"
local xresources = require "beautiful.xresources"
local dpi = xresources.apply_dpi


local ws = obj {
    enable_properties = true,
    enable_auto_signals = true
}

ws.selected = 1
ws.max = 0

local widget = awful.popup {
    widget = {
        {
            widget = awful.widget.tasklist {
                screen   = screen[1],
                filter   = awful.widget.tasklist.filter.allscreen,
                style    = {
                    shape = vars.shape,
                },
                layout   = {
                    forced_num_rows = 1,
                    layout = wibox.layout.grid.vertical,
                    spacing = vars.padding
                },
                widget_template = {
                    {
                        layout = wibox.layout.align.horizontal,
                        {
                            widget = wibox.container.place,
                            {
                                widget = wibox.container.margin,
                                margins = dpi(6),
                                {
                                    id = "text_role",
                                    widget = wibox.widget.textbox,
                                }
                            }
                        },
                        nil,
                        {
                            widget = wibox.container.place,
                            {
                                widget = wibox.container.margin,
                                margins = dpi(6),
                                {
                                    id = "tag_role",
                                    widget = wibox.widget.textbox,
                                }
                            }
                        }
                    },
                    forced_width = dpi(screen[1].geometry.width / 8),
                    bg = vars.colors.black,
                    border_width = vars.border_width,
                    border_color = vars.colors.black,
                    shape = vars.shape,
                    widget = wibox.container.background,
                    create_callback = function(self, client, i)
                        -- self:get_children_by_id("name_role")[1].text = client.name
                        self:get_children_by_id("tag_role")[1].text = client.first_tag.name

                        ws:connect_signal("property::selected", function(selected)
                            naughty.notification {
                                urgency = "critical",
                                message = tostring(selected) .. " | " .. tostring(i)
                            }
                        
                            if selected == i then
                                self.border_color = vars.colors.yellow
                            else 
                                self.border_color = vars.colors.black
                            end
                        end)
                    end
                    -- update_callback = function(self, _, i)
                    --     if ws.selected == i then
                    --         self.border_color = vars.colors.yellow
                    --     else 
                    --         self.border_color = vars.colors.black
                    --     end
                    -- end
                }
            },
            id = "tasklist"
        },
        widget = wibox.container.margin,
        margins = vars.padding
    },
    border_color =  vars.colors.bright.black,
    border_width = vars.border_width,
    ontop = true,
    placement = awful.placement.centered,
    bg = vars.colors.bg,
    shape = vars.shape,
    visible = false
}

ws.widget = widget

ws.max = ws.widget.widget.tasklist.count



-- ws.widget:connect_signal("property::count", function(self)
--     naughty.notification {
--         urgency = "critical",
--         message = tostring(ws.max)
--     }
--     ws.max = self.count
-- end)

awful.keygrabber {
    keybindings = {
        awful.key {
            modifiers = { "Mod1" },
            key = "Tab",
            on_press = function()
                -- naughty.notification {
                --     urgency = "critical",
                --     message = tostring(WS.widget)
                -- }
                naughty.notification {
                    urgency = "critical",
                    message = tostring(ws.selected)
                }
                -- local file = io.open("/home/delta/.cache/awesome/tasklist_dump.txt", "w+")
                -- file:write(debug.dump_return(WS.widget, "tasklist"))
                -- file:close()
                -- ws.widget:emit_signal_recursive("widget::layout_changed")
                -- WS.widget:emit_signal("widget::redraw_needed")
                if ws.selected + 1 > ws.max then
                    ws.selected = 1
                    return
                end
                ws.selected = ws.selected + 1
            end
        },
        awful.key {
            modifiers = { "Mod1", "Shift" },
            key = "Tab",
            on_press = function()
                ws.widget:emit_signal("widget::layout_changed")
                if ws.selected - 1 == 0 then
                    ws.selected = ws.max
                    return
                end
                ws.selected = ws.selected - 1
            end
        },
    },
    stop_key = "Mod1",
    stop_event = "release",
    start_callback = function()
        ws.widget.visible = true
        naughty.notification {
    urgency = "critical",
    message = tostring(ws.max)
}
    end,
    stop_callback = function()
        ws.widget.visible = false
    end,
    autostart = false
}