init: window finder

This commit is contained in:
Makesesama 2025-05-15 23:29:20 +02:00
parent 82b0cf7aaa
commit 5d08a48b6c
4 changed files with 95 additions and 9 deletions

View File

@ -1,24 +1,75 @@
import operator
from fabric.widgets.wayland import WaylandWindow as Window from fabric.widgets.wayland import WaylandWindow as Window
from fabric.widgets.box import Box from fabric.widgets.box import Box
from fabric.widgets.label import Label 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): class FuzzyWindowFinder(Window):
def __init__( def __init__(
self, self,
monitor: int = 1, monitor: int = 0,
): ):
super().__init__( super().__init__(
name="finder", name="finder",
layer="overlay",
anchor="center", anchor="center",
margin="0px 0px -2px 0px",
exclusivity="auto",
visible=False,
all_visible=False,
monitor=monitor, monitor=monitor,
keyboard_mode="on-demand",
type="popup",
visible=False,
) )
self.children = Box( self._all_windows = ["Test", "Uwu", "Tidal"]
name="list-windows", children=[Label(name="one-window", markup="Hallo lol")]
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)])
)

29
bar/styles/finder.css Normal file
View File

@ -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 */
}

View File

@ -3,6 +3,7 @@
@import url("./menu.css"); @import url("./menu.css");
@import url("./vinyl.css"); @import url("./vinyl.css");
@import url("./bar.css"); @import url("./bar.css");
@import url("./finder.css");
/* unset so we can style everything from the ground up. */ /* unset so we can style everything from the ground up. */

View File

@ -32,7 +32,12 @@
{ {
formatter = pkgs.nixfmt-rfc-style; formatter = pkgs.nixfmt-rfc-style;
devShells.default = pkgs.callPackage ./nix/shell.nix { inherit pkgs; }; 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 = { apps.default = {
type = "app"; type = "app";
program = "${self.packages.${system}.default}/bin/bar"; program = "${self.packages.${system}.default}/bin/bar";