By using this site, you agree to have cookies stored on your device, strictly for functional purposes, such as storing your session and preferences.

Dismiss

 __init__.py

View raw Download
text/x-script.python • 4.25 kiB
Python script, ASCII text executable
        
            
1
import os
2
from pathlib import Path
3
import wayfire
4
import panorama_panel
5
6
import gi
7
from wayfire import WayfireSocket
8
9
gi.require_version("Gtk", "4.0")
10
11
from gi.repository import Gtk, GLib, Gio, Gdk
12
13
14
module_directory = Path(__file__).resolve().parent
15
16
17
"""
18
@Gtk.Template(filename=str(module_directory / "panorama-clock-options.ui"))
19
class ClockOptions(Gtk.Window):
20
__gtype_name__ = "ClockOptions"
21
format_entry: Gtk.Entry = Gtk.Template.Child()
22
23
def __init__(self, **kwargs):
24
super().__init__(**kwargs)
25
26
self.connect("close-request", lambda *args: self.destroy())
27
"""
28
29
30
class WindowButton(Gtk.ToggleButton):
31
def __init__(self, window_id, window_title, **kwargs):
32
super().__init__(**kwargs)
33
34
self.window_id = window_id
35
self.window_title = window_title
36
37
self.set_label(self.window_title)
38
39
40
class WFWindowList(panorama_panel.Applet):
41
name = "Wayfire window list"
42
description = "Traditional window list (for Wayfire)"
43
44
def __init__(self, orientation=Gtk.Orientation.HORIZONTAL, config=None):
45
super().__init__(orientation=orientation, config=config)
46
if config is None:
47
config = {}
48
49
self.socket = WayfireSocket()
50
self.socket.watch()
51
fd = self.socket.client.fileno()
52
GLib.io_add_watch(fd, GLib.IO_IN, self.on_wf_event)
53
54
self.window_buttons = {}
55
56
for view in self.socket.list_views():
57
self.create_window_button(view)
58
59
self.context_menu = self.make_context_menu()
60
panorama_panel.track_popover(self.context_menu)
61
62
right_click_controller = Gtk.GestureClick()
63
right_click_controller.set_button(3)
64
right_click_controller.connect("pressed", self.show_context_menu)
65
66
self.add_controller(right_click_controller)
67
68
action_group = Gio.SimpleActionGroup()
69
options_action = Gio.SimpleAction.new("options", None)
70
options_action.connect("activate", self.show_options)
71
action_group.add_action(options_action)
72
self.insert_action_group("applet", action_group)
73
74
self.options_window = None
75
76
def create_window_button(self, view):
77
button = WindowButton(view["id"], view["title"])
78
79
self.window_buttons[view["id"]] = button
80
self.append(button)
81
82
def remove_window_button(self, view):
83
self.remove(self.window_buttons[view["id"]])
84
self.window_buttons[view["id"]] = None
85
86
def on_wf_event(self, source, condition):
87
if condition == GLib.IO_IN:
88
try:
89
message = self.socket.read_next_event()
90
event = message.get("event")
91
view = message.get("view", {})
92
print(f"[{event}] {view.get('app-id')} - {view.get('title')}")
93
match event:
94
case "view-mapped":
95
self.create_window_button(message["view"])
96
case "view-unmapped":
97
self.remove_window_button(message["view"])
98
except Exception as e:
99
print("Error reading Wayfire event:", e)
100
return True
101
102
def make_context_menu(self):
103
menu = Gio.Menu()
104
menu.append("Window list _options", "applet.options")
105
context_menu = Gtk.PopoverMenu.new_from_model(menu)
106
context_menu.set_has_arrow(False)
107
context_menu.set_parent(self)
108
context_menu.set_halign(Gtk.Align.START)
109
context_menu.set_flags(Gtk.PopoverMenuFlags.NESTED)
110
return context_menu
111
112
def show_context_menu(self, gesture, n_presses, x, y):
113
rect = Gdk.Rectangle()
114
rect.x = int(x)
115
rect.y = int(y)
116
rect.width = 1
117
rect.height = 1
118
119
self.context_menu.set_pointing_to(rect)
120
self.context_menu.popup()
121
122
def show_options(self, _0=None, _1=None):
123
"""
124
if self.options_window is None:
125
self.options_window = ClockOptions()
126
self.options_window.format_entry.set_text(self.formatting)
127
self.options_window.format_entry.connect("changed", self.update_formatting)
128
129
def reset_window(*args):
130
self.options_window = None
131
132
self.options_window.connect("close-request", reset_window)
133
self.options_window.present()
134
"""
135
136
def get_config(self):
137
return {}
138