From 3aa3187263e372e6ec04717cf7a007828ddc48bc Mon Sep 17 00:00:00 2001 From: Mircea Pop Date: Fri, 10 Apr 2026 09:18:43 +0200 Subject: [PATCH] Add configurable window position setting The picker window always opens centered on the primary monitor, which is inconvenient on multi-monitor setups where the user may be working on a different screen. This adds a "Window Position" preference with two options: "Center" (existing default behavior) and "Mouse Cursor" (opens the picker at the current pointer location). --- emote/picker.py | 11 ++++++++++- emote/settings.py | 21 +++++++++++++++++++++ emote/user_data.py | 14 ++++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) diff --git a/emote/picker.py b/emote/picker.py index 21c1cda..b4a8c0e 100644 --- a/emote/picker.py +++ b/emote/picker.py @@ -26,12 +26,21 @@ def grouper(iterable, n, fillvalue=None): return zip_longest(*args, fillvalue=fillvalue) +WINDOW_POSITION_MAP = { + "Center": Gtk.WindowPosition.CENTER, + "Mouse Cursor": Gtk.WindowPosition.MOUSE, +} + + class EmojiPicker(Gtk.Window): def __init__(self, open_time, update_accelerator, update_theme, show_welcome): + window_position = WINDOW_POSITION_MAP.get( + user_data.load_window_position(), Gtk.WindowPosition.CENTER + ) Gtk.Window.__init__( self, title="Emote", - window_position=Gtk.WindowPosition.CENTER, + window_position=window_position, resizable=False, deletable=False, name="emote_window", diff --git a/emote/settings.py b/emote/settings.py index 4764484..20992ed 100644 --- a/emote/settings.py +++ b/emote/settings.py @@ -47,6 +47,21 @@ def __init__(self, update_theme): settings_grid.attach(theme_combo, 2, row, 1, 1) row += 1 + window_position_label = Gtk.Label("Window Position") + window_position_label.set_alignment(0, 0.5) + settings_grid.attach(window_position_label, 1, row, 1, 1) + + window_position_combo = Gtk.ComboBoxText() + window_position_combo.set_entry_text_column(0) + window_position_combo.connect("changed", self.on_window_position_combo_changed) + for position in user_data.WINDOW_POSITIONS: + window_position_combo.append_text(position) + window_position_combo.set_active( + user_data.WINDOW_POSITIONS.index(user_data.load_window_position()) + ) + settings_grid.attach(window_position_combo, 2, row, 1, 1) + row += 1 + box.pack_start(settings_grid, True, True, GRID_SIZE) self.show_all() @@ -57,3 +72,9 @@ def on_theme_combo_changed(self, combo): if theme is not None: self.update_theme(theme) + + def on_window_position_combo_changed(self, combo): + window_position = combo.get_active_text() + + if window_position is not None: + user_data.update_window_position(window_position) diff --git a/emote/user_data.py b/emote/user_data.py index 271291c..1576d9a 100644 --- a/emote/user_data.py +++ b/emote/user_data.py @@ -68,6 +68,10 @@ DEFAULT_SKINTONE_INDEX = 0 SKINTONES = ["✋", "✋🏻", "✋🏼", "✋🏽", "✋🏾", "✋🏿"] +WINDOW_POSITION = "window_position" +DEFAULT_WINDOW_POSITION = "Center" +WINDOW_POSITIONS = ["Center", "Mouse Cursor"] + # Ensure the data dir exists os.makedirs(DATA_DIR, exist_ok=True) @@ -134,3 +138,13 @@ def load_skintone_index(): def update_skintone_index(skintone): with shelve.open(SHELVE_PATH) as db: db[SKINTONE_INDEX] = skintone + + +def load_window_position(): + with shelve.open(SHELVE_PATH) as db: + return db.get(WINDOW_POSITION, DEFAULT_WINDOW_POSITION) + + +def update_window_position(window_position): + with shelve.open(SHELVE_PATH) as db: + db[WINDOW_POSITION] = window_position