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