diff options
author | B Stack <bgstack15@gmail.com> | 2020-04-03 20:49:04 -0400 |
---|---|---|
committer | B Stack <bgstack15@gmail.com> | 2020-04-03 20:49:04 -0400 |
commit | 9cbdffbf330b2892d7573bf94e83cf343e7d4d20 (patch) | |
tree | 9ca33ba80af54da723daed9f3ecd2bf80d448335 | |
parent | Merge branch 'dev' into 'master' (diff) | |
download | logout-manager-9cbdffbf330b2892d7573bf94e83cf343e7d4d20.tar.gz logout-manager-9cbdffbf330b2892d7573bf94e83cf343e7d4d20.tar.bz2 logout-manager-9cbdffbf330b2892d7573bf94e83cf343e7d4d20.zip |
works with libxappsuse-xapps
Needs python3-xapp? for run-time. Needs comments cleaned up. The
current double-click detection is clunky, but that is an libxapp
weakness right now.
-rwxr-xr-x | src/usr/bin/logout-manager-trayicon | 42 |
1 files changed, 32 insertions, 10 deletions
diff --git a/src/usr/bin/logout-manager-trayicon b/src/usr/bin/logout-manager-trayicon index 9eaaa32..39f1edd 100755 --- a/src/usr/bin/logout-manager-trayicon +++ b/src/usr/bin/logout-manager-trayicon @@ -19,6 +19,7 @@ # find running processes https://thispointer.com/python-get-list-of-all-running-processes-and-sort-by-highest-memory-usage/ # send signals https://stackoverflow.com/questions/15080500/how-can-i-send-a-signal-from-a-python-program # https://docs.python.org/3.8/library/signal.html#module-signal +# XApp examples https://github.com/linuxmint/xapps/blob/master/test-scripts/xapp-status-icon-variants/xapp-status-icon-all-menus # Dependencies: # dep-pip: psutil, distro # dep-devuan: python3-psutil, python3-distro @@ -26,8 +27,9 @@ import gi, os, re, sys, psutil, signal from distro import linux_distribution gi.require_version("Gtk","3.0") -from gi.repository import Gtk -from gi.repository import Gdk +import xapp +gi.require_version("XApp","1.0") +from gi.repository import Gtk, Gdk, XApp from dotenv import load_dotenv # all this to load the libpath @@ -84,12 +86,12 @@ def run_or_kill_logout_manager(): newpid = os.spawnvp(os.P_NOWAIT,"logout-manager",["logout-manager","--from-trayicon"]) print("spawned",newpid) -class MainIcon(Gtk.StatusIcon): +class MainIcon(XApp.StatusIcon): def __init__(self,config,actions): - Gtk.StatusIcon.__init__(self) + XApp.StatusIcon.__init__(self) self.config = config self.actions = actions - self.set_from_icon_name(self.config.get_logout_icon()) + self.set_icon_name(self.config.get_logout_icon()) loggedin_str = "Logged in as " + str(os.environ["USER"]) tooltiptext = loggedin_str if is_dryrun(): @@ -102,6 +104,7 @@ class MainIcon(Gtk.StatusIcon): self.add_action_to_menu("_Hibernate",self.config.get_hibernate_icon(),self.on_hibernate_menuitem) self.add_action_to_menu("_Shutdown",self.config.get_shutdown_icon(),self.on_shutdown_menuitem) self.add_action_to_menu("_Reboot",self.config.get_reboot_icon(),self.on_reboot_menuitem) + self.LAST_CLICK_TIMESTAMP = 0 # separator i = Gtk.SeparatorMenuItem.new() @@ -121,11 +124,30 @@ class MainIcon(Gtk.StatusIcon): self.traymenu.append(i) self.connect("button-press-event", self.on_button_press_event) - self.connect("popup-menu", self.show_menu) - - def on_button_press_event(self, b_unknown, event: Gdk.EventButton): - if Gdk.EventType._2BUTTON_PRESS == event.type: - run_or_kill_logout_manager() + #self.connect("popup-menu", self.show_menu) + self.set_secondary_menu(self.traymenu) + + #def on_button_press_event(a, b_unknown, event: Gdk.EventButton, c, d, e, f): + def on_button_press_event(a, b, c, d, e, f, g): + # param 4 is a static int? "17" + # param 5 is the useful one + # param 6 is a timestamp + print("A",a) + print("b", b) + print("c", c) + print("d", d) + print("e", e) + print("f", f) + print("g", g) + this_timestamp = f + if e == 1: + if a.LAST_CLICK_TIMESTAMP == f: + print("Double click!") + #run_or_kill_logout_manager() + a.LAST_CLICK_TIMESTAMP = f + + #if d == 1 and Gdk.EventType._2BUTTON_PRESS == event.type: + # run_or_kill_logout_manager() def exit(self, widget): quit() |