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

Implement focused window display

roundabout,
created on Saturday, 26 July 2025, 17:54:49 (1753552489), received on Saturday, 26 July 2025, 17:54:56 (1753552496)
Author identity: vlad <vlad.muntoiu@gmail.com>

a111cb2bf99d57b9130dc3e766421b25f1305c88

applets/wf-window-list/__init__.py

@@ -1,3 +1,4 @@

                                
                                
                                
                            
                                
                                    
                                        
                                        import dataclasses
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            import os
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            from pathlib import Path
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            from pywayland.client import Display
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        

@@ -18,18 +19,66 @@ from gi.repository import Gtk, GLib, Gio, Gdk

                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            module_directory = Path(__file__).resolve().parent
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        def split_bytes_into_ints(array: bytes, size: int = 4) -> list[int]:
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            if len(array) % size:
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                raise ValueError(f"The byte string's length must be a multiple of {size}")
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            values: list[int] = []
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            for i in range(0, len(array), size):
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                values.append(int.from_bytes(array[i : i+size], byteorder="little"))
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            return values
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        @dataclasses.dataclass
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        class WindowState:
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            minimised: bool
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            maximised: bool
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            fullscreen: bool
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            focused: bool
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            @classmethod
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            def from_state_array(cls, array: bytes):
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                values = split_bytes_into_ints(array)
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                instance = WindowState(False, False, False, False)
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                print(values)
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                for value in values:
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                    match value:
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                        case 0:
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                            instance.maximised = True
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                        case 1:
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                            instance.minimised = True
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                        case 2:
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                            instance.focused = True
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                        case 3:
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                            instance.fullscreen = True
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                return instance
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            class WindowButton(Gtk.ToggleButton):
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                def __init__(self, window_id, window_title, **kwargs):
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                    super().__init__(**kwargs)
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                    self.window_id = window_id
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                self.window_title = window_title
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                    self.set_has_frame(False)
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                self.label = Gtk.Label()
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                box = Gtk.Box()
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                box.append(self.label)
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                self.set_child(box)
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                self.set_label(self.window_title)
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                self.window_title = window_title
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                    self.last_state = False
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            @property
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            def window_title(self):
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                return self.label.get_text()
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            @window_title.setter
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            def window_title(self, value):
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                self.label.set_text(value)
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            class WFWindowList(panorama_panel.Applet):
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                name = "Wayfire window list"
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        

@@ -90,17 +139,31 @@ class WFWindowList(panorama_panel.Applet):

                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                    print("Toplevel received")
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                    handle.dispatcher["title"] = lambda h, title: self.on_title_changed(h, title)
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                    #handle.dispatcher["app_id"] = lambda h, app_id: self.on_app_id_changed(h, app_id)
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                #handle.dispatcher["state"] = lambda h, states: self.on_state_changed(h, states)
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                handle.dispatcher["state"] = lambda h, states: self.on_state_changed(h, states)
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                    handle.dispatcher["closed"] = lambda h: self.on_closed(h)
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                def on_title_changed(self, handle, title):
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                    print(f"Window title: {title}")
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                    if handle not in self.toplevel_buttons:
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                    button = WindowButton(id(handle), title)
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                    button = WindowButton(handle, title)
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                        button.set_group(self.initial_button)
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                        button.connect("clicked", lambda *a: self.on_button_click(handle))
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                        self.toplevel_buttons[handle] = button
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                        self.append(button)
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                else:
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                    button = self.toplevel_buttons[handle]
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                    button.window_title = title
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            def on_state_changed(self, handle, states):
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                if handle in self.toplevel_buttons:
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                    state_info = WindowState.from_state_array(states)
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                    print(state_info)
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                    button = self.toplevel_buttons[handle]
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                    if state_info.focused:
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                        print("focused")
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                        button.set_active(True)
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                    else:
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                        self.initial_button.set_active(True)
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                def on_closed(self, handle):
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                    if handle in self.toplevel_buttons: