diff --git a/bar/modules/window_fuzzy.py b/bar/modules/window_fuzzy.py index 254d0ce..20dfe12 100644 --- a/bar/modules/window_fuzzy.py +++ b/bar/modules/window_fuzzy.py @@ -1,24 +1,75 @@ +import operator from fabric.widgets.wayland import WaylandWindow as Window from fabric.widgets.box import Box from fabric.widgets.label import Label +from fabric.widgets.entry import Entry +from fabric.utils import idle_add +from gi.repository import Gdk class FuzzyWindowFinder(Window): def __init__( self, - monitor: int = 1, + monitor: int = 0, ): super().__init__( name="finder", - layer="overlay", anchor="center", - margin="0px 0px -2px 0px", - exclusivity="auto", - visible=False, - all_visible=False, monitor=monitor, + keyboard_mode="on-demand", + type="popup", + visible=False, ) - self.children = Box( - name="list-windows", children=[Label(name="one-window", markup="Hallo lol")] + self._all_windows = ["Test", "Uwu", "Tidal"] + + self.viewport = Box(name="viewport", spacing=4, orientation="v") + + self.search_entry = Entry( + name="search-entry", + placeholder="Search Windows...", + h_expand=True, + editable=True, + notify_text=self.notify_text, + on_activate=lambda entry, *_: self.on_search_entry_activate( + entry.get_text() + ), + on_key_press_event=self.on_search_entry_key_press, ) + self.picker_box = Box( + name="picker-box", + spacing=4, + orientation="v", + children=[self.search_entry, self.viewport], + ) + + self.add(self.picker_box) + self.arrange_viewport("") + + def notify_text(self, entry, *_): + text = entry.get_text() + self.arrange_viewport(text) # Update list on typing + print(text) + + def on_search_entry_key_press(self, widget, event): + # if event.keyval in (Gdk.KEY_Up, Gdk.KEY_Down, Gdk.KEY_Left, Gdk.KEY_Right): + # self.move_selection_2d(event.keyval) + # return True + print(event.keyval) + if event.keyval in [Gdk.KEY_Escape, 103]: + self.hide() + return True + return False + + def on_search_entry_activate(self, text): + print(f"activate {text}") + + def arrange_viewport(self, query: str = ""): + self.viewport.children = [] # Clear previous entries + + filtered = [w for w in self._all_windows if query.lower() in w.lower()] + + for window in filtered: + self.viewport.add( + Box(name="slot-box", orientation="h", children=[Label(label=window)]) + ) diff --git a/bar/styles/finder.css b/bar/styles/finder.css new file mode 100644 index 0000000..25414f0 --- /dev/null +++ b/bar/styles/finder.css @@ -0,0 +1,29 @@ +#picker-box { + padding: 12px; + background-color: rgba(40, 40, 40, 0.95); /* darker for contrast */ + border-radius: 8px; + font-family: sans-serif; + font-size: 14px; + color: white; +} + + +#viewport { + padding: 8px; + background-color: rgba(30, 30, 30, 0.9); /* dark background for contrast */ + border-radius: 6px; + font-family: sans-serif; + font-size: 14px; + color: white; /* ensure contrast */ +} + +#viewport > * { + padding: 6px 10px; + margin-bottom: 4px; + border-radius: 4px; + background-color: rgba(255, 255, 255, 0.05); +} + +#viewport:hover { + background-color: rgba(255, 255, 255, 0.15); /* hover feedback */ +} diff --git a/bar/styles/main.css b/bar/styles/main.css index 0af1140..e496b4d 100644 --- a/bar/styles/main.css +++ b/bar/styles/main.css @@ -3,6 +3,7 @@ @import url("./menu.css"); @import url("./vinyl.css"); @import url("./bar.css"); +@import url("./finder.css"); /* unset so we can style everything from the ground up. */ diff --git a/flake.nix b/flake.nix index 52ef38f..97c77c6 100644 --- a/flake.nix +++ b/flake.nix @@ -32,7 +32,12 @@ { formatter = pkgs.nixfmt-rfc-style; devShells.default = pkgs.callPackage ./nix/shell.nix { inherit pkgs; }; - packages.default = pkgs.callPackage ./nix/derivation.nix { inherit (pkgs) lib python3Packages; }; + packages = { + default = pkgs.callPackage ./nix/derivation.nix { inherit (pkgs) lib python3Packages; }; + makku = pkgs.writeShellScriptBin "makku" '' + dbus-send --session --print-reply --dest=org.Fabric.fabric.bar /org/Fabric/fabric org.Fabric.fabric.Evaluate string:"finder.show()" > /dev/null 2>&1 + ''; + }; apps.default = { type = "app"; program = "${self.packages.${system}.default}/bin/bar";