Skip to content

Commit

Permalink
Copy address to clipboard from manager device list
Browse files Browse the repository at this point in the history
  • Loading branch information
cschramm committed Feb 19, 2024
1 parent 228fe98 commit 9a1104b
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions blueman/gui/manager/ManagerDeviceList.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,9 @@ def __init__(self, inst: "Blueman", adapter: Optional[str] = None) -> None:
self.tooltip_col: Optional[Gtk.TreeViewColumn] = None

self.connect("popup-menu", self._on_popup_menu)
self.connect("button_press_event", self.on_event_clicked)
self.connect("button_release_event", self.on_event_clicked)
self.connect("button-press-event", self._on_event_clicked)
self.connect("button-release-event", self._on_event_clicked)
self.connect("key-press-event", self._on_key_pressed)

self.menu: Optional[ManagerDeviceMenu] = None

Expand Down Expand Up @@ -217,7 +218,7 @@ def _on_popup_menu(self, _widget: Gtk.Widget) -> bool:

return True

def on_event_clicked(self, _widget: Gtk.Widget, event: Gdk.Event) -> bool:
def _on_event_clicked(self, _widget: Gtk.Widget, event: Gdk.Event) -> bool:
if event.type not in (Gdk.EventType._2BUTTON_PRESS, Gdk.EventType.BUTTON_PRESS):
return False

Expand Down Expand Up @@ -251,6 +252,21 @@ def on_event_clicked(self, _widget: Gtk.Widget, event: Gdk.Event) -> bool:

return False

def _on_key_pressed(self, _widget: Gtk.Widget, event: Gdk.EventKey) -> bool:
if not (event.state & Gdk.ModifierType.CONTROL_MASK and event.keyval == Gdk.KEY_c):
return False

selected = self.selected()
if not selected:
return False

row = self.get(selected, "device")
if not row:
return False

Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD).set_text(row["device"]["Address"], -1)
return True

def _load_surface(self, icon_name: str, size: int) -> cairo.ImageSurface:
window = self.get_window()
scale = self.get_scale_factor()
Expand Down

0 comments on commit 9a1104b

Please sign in to comment.