__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 36 37self.set_label(self.window_title) 38 39 40class WFWindowList(panorama_panel.Applet): 41name = "Wayfire window list" 42description = "Traditional window list (for Wayfire)" 43 44def __init__(self, orientation=Gtk.Orientation.HORIZONTAL, config=None): 45super().__init__(orientation=orientation, config=config) 46if config is None: 47config = {} 48 49self.socket = WayfireSocket() 50self.socket.watch() 51fd = self.socket.client.fileno() 52GLib.io_add_watch(fd, GLib.IO_IN, self.on_wf_event) 53 54self.window_buttons = {} 55 56for view in self.socket.list_views(): 57self.create_window_button(view) 58 59self.context_menu = self.make_context_menu() 60panorama_panel.track_popover(self.context_menu) 61 62right_click_controller = Gtk.GestureClick() 63right_click_controller.set_button(3) 64right_click_controller.connect("pressed", self.show_context_menu) 65 66self.add_controller(right_click_controller) 67 68action_group = Gio.SimpleActionGroup() 69options_action = Gio.SimpleAction.new("options", None) 70options_action.connect("activate", self.show_options) 71action_group.add_action(options_action) 72self.insert_action_group("applet", action_group) 73 74self.options_window = None 75 76def create_window_button(self, view): 77button = WindowButton(view["id"], view["title"]) 78 79self.window_buttons[view["id"]] = button 80self.append(button) 81 82def remove_window_button(self, view): 83self.remove(self.window_buttons[view["id"]]) 84self.window_buttons[view["id"]] = None 85 86def on_wf_event(self, source, condition): 87if condition == GLib.IO_IN: 88try: 89message = self.socket.read_next_event() 90event = message.get("event") 91view = message.get("view", {}) 92print(f"[{event}] {view.get('app-id')} - {view.get('title')}") 93match event: 94case "view-mapped": 95self.create_window_button(message["view"]) 96case "view-unmapped": 97self.remove_window_button(message["view"]) 98except Exception as e: 99print("Error reading Wayfire event:", e) 100return True 101 102def make_context_menu(self): 103menu = Gio.Menu() 104menu.append("Window list _options", "applet.options") 105context_menu = Gtk.PopoverMenu.new_from_model(menu) 106context_menu.set_has_arrow(False) 107context_menu.set_parent(self) 108context_menu.set_halign(Gtk.Align.START) 109context_menu.set_flags(Gtk.PopoverMenuFlags.NESTED) 110return context_menu 111 112def show_context_menu(self, gesture, n_presses, x, y): 113rect = Gdk.Rectangle() 114rect.x = int(x) 115rect.y = int(y) 116rect.width = 1 117rect.height = 1 118 119self.context_menu.set_pointing_to(rect) 120self.context_menu.popup() 121 122def show_options(self, _0=None, _1=None): 123""" 124if self.options_window is None: 125self.options_window = ClockOptions() 126self.options_window.format_entry.set_text(self.formatting) 127self.options_window.format_entry.connect("changed", self.update_formatting) 128 129def reset_window(*args): 130self.options_window = None 131 132self.options_window.connect("close-request", reset_window) 133self.options_window.present() 134""" 135 136def get_config(self): 137return {} 138