gromit-mpx icon indicating copy to clipboard operation
gromit-mpx copied to clipboard

Make the menu accessible on stock GNOME3 as well

Open bk138 opened this issue 4 years ago • 6 comments

Stock GNOME3 does not show any tray icon at all, thus there's no way to actually access the menu. Explore possibilities to make this happen.

Approach 1 - via Dock Icon -> :no_entry:

  • when there is a GTK_WINDOW_TOPLEVEL window, an icon is shown in the dock
  • activation could open the menu
  • or: explore .desktop actions

-> folllowing patch has desktop actions:

diff --git a/data/net.christianbeier.Gromit-MPX.desktop b/data/net.christianbeier.Gromit-MPX.desktop
index 2ac3a24..6097856 100644
--- a/data/net.christianbeier.Gromit-MPX.desktop
+++ b/data/net.christianbeier.Gromit-MPX.desktop
@@ -9,3 +9,9 @@ Keywords=presentation;overlay;markup;pointer;
 Terminal=false
 StartupNotify=false
 Categories=Graphics;
+
+Actions=Toggle;
+
+[Desktop Action Toggle]
+Name=Toggl
+Exec=gromit-mpx -t
\ No newline at end of file
diff --git a/src/callbacks.c b/src/callbacks.c
index 0498b33..36d4324 100644
--- a/src/callbacks.c
+++ b/src/callbacks.c
@@ -412,9 +412,19 @@ void on_mainapp_selection_get (GtkWidget          *widget,
   if(action == GA_TOGGLE)
     {
       /* ask back client for device id */
-      gtk_selection_convert (data->win, GA_DATA,
-                             GA_TOGGLEDATA, time);
-      gtk_main(); /* Wait for the response */
+      //gtk_selection_convert (data->win, GA_DATA,
+	//                      GA_TOGGLEDATA, time);
+      //gtk_main(); /* Wait for the response */
+
+        gtk_menu_popup_at_pointer(data->menu, NULL);
+        
+	/*
+	gtk_menu_popup_at_widget (data->menu,
+                          data->dummy,
+                         GDK_GRAVITY_CENTER,
+                          GDK_GRAVITY_CENTER,
+                          NULL);
+	*/
     }
   else if (action == GA_VISIBILITY)
     toggle_visibility (data);
diff --git a/src/gromit-mpx.c b/src/gromit-mpx.c
index 81319b9..b98d95f 100644
--- a/src/gromit-mpx.c
+++ b/src/gromit-mpx.c
@@ -955,6 +955,7 @@ void setup_main_app (GromitData *data, int argc, char ** argv)
 
   /* create the menu */
   GtkWidget *menu = gtk_menu_new ();
+  data->menu = menu;
 
   char labelBuf[128];
   /* Create the menu items */
@@ -1219,7 +1220,11 @@ int main (int argc, char **argv)
   /*
     init our window
   */
-  data->win = gtk_window_new (GTK_WINDOW_POPUP);
+   data->win = gtk_window_new (GTK_WINDOW_POPUP);
+
+  data->dummy = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+  gtk_widget_show (data->dummy);
+  
   // this trys to set an alpha channel
   on_screen_changed(data->win, NULL, data);
 
diff --git a/src/gromit-mpx.h b/src/gromit-mpx.h
index f060163..6345f03 100644
--- a/src/gromit-mpx.h
+++ b/src/gromit-mpx.h
@@ -99,7 +99,8 @@ typedef struct
 {
   GtkWidget   *win;
   AppIndicator *trayicon;
-
+    GtkMenu *menu;
+    GtkWidget   *dummy;
   GdkCursor   *paint_cursor;
   GdkCursor   *erase_cursor;

--> -t toggle from cmdlne opens menu, is also called from desktop entry, but menu does not open in GNOME's app overview mode: :no_entry:

--> also,dock icon needs a toplevel window. we could make this transparent and undecorated, but it would still show up in the app overview :no_entry: :-(

Approach 2 - via a persistent notification -> :no_entry:

  • which on click shows the menu - but where?
  • libnotify notifications can be persistent, but they're always closable :-1: we could maybe add an on-close listener and re-open, but that's not nice UX :no_entry:
    • re-open on close works, but the action buttons are not shown in the drawer thing that opens on clicking the clock :-( :no_entry: :no_entry:
    • but action "default" works :tada:
  • cannot open menu on click using https://developer.gnome.org/gtk3/stable/GtkMenu.html#gtk-menu-popup-at-pointer : gtk_menu_popup_at_rect: assertion 'GDK_IS_WINDOW (rect_window)' failed :-1:
  • gtk_menu_popup_at_widget () also does not work as the menu can only be popped up relative to data->win, but not to the pointer :-( -> bad UX

Approach 3 - via Shell Extension :no_entry:

  • https://askubuntu.com/a/591764/344291
  • https://github.com/flatpak/xdg-desktop-portal/issues/283
  • https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/2689
  • https://flathub.org/apps/details/org.gnome.Extensions is able to read and delete extensions
    • https://github.com/flathub/org.gnome.Extensions/blob/master/org.gnome.Extensions.json
    • https://gitlab.gnome.org/GNOME/gnome-shell/-/tree/master/subprojects/extensions-app
    • https://gitlab.gnome.org/GNOME/gnome-shell/blob/master/data/dbus-interfaces/org.gnome.Shell.Extensions.xml lists possible dbus actions (only remote install, but uninstall)

copy shell extension code from flatpak to host :heavy_check_mark:

  • dest: ~/.local/share/gnome-shell/extensions
  • fb32a5bca021164dd06a43783da400aa3b2ae1b8 :heavy_check_mark:

make shell extension known to GNOME :no_entry:

  • restart GNOME works but :no_good:
    • https://stackoverflow.com/questions/46565019/how-to-properly-start-a-gnome-shell-extension-via-command-line?rq=1
  • https://stackoverflow.com/questions/62265594/gnome-shell-extension-install-possible-without-restart but not possible to run this :no_entry:
  • https://pypi.org/project/gnome-extensions-cli/ displays a dialog if installing from web :no_entry:
  • https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/906#note_451156

toggle shell extension on/off from flatpak :heavy_check_mark:

flatpak run --talk-name=org.freedesktop.Flatpak --command=bash net.christianbeier.Gromit-MPX and then flatpak-spawn --host gnome-shell-extension-tool -e [email protected]; flatpak-spawn --host gnome-shell-extension-tool -d [email protected] :heavy_check_mark:

Approach 4 re-use the menu

  • existing menu popup on button press works but bad UI ⛔
  • use gtkmenubar with vertical direction to embed same menu
    • https://stackoverflow.com/questions/3003655/is-there-a-good-way-to-copy-a-gtk-widget
    • https://stackoverflow.com/questions/2645850/how-to-copy-or-duplicate-gtk-widgets?noredirect=1&lq=1
    • --> not possible to copy gtkmenuitem ⛔
    • --> also not possible to attach an already attached gtkmenuitem ⛔
    • construction both the tray menu and the windowed menubar menu from a gmenu would work
      • but callbacks would need to be GActions

bk138 avatar Dec 05 '20 20:12 bk138

I'm on XCFE4 (Ubuntu 20.10) and see no notification/tray icon either. It would be nice to have a CLI switch that simply shows a simple GUI window. I know the philosophy is "keep the desktop clean" but an opt-in window would be acceptable, and help whenever there are these types of issues.

I've just tried this program tonight and am already prevented from continuing due to the tray issue, and the hotkeys not binding. Not sure what to do now.

Seeing this in the console:

(gromit-mpx:114962): libappindicator-CRITICAL **: 23:16:33.585: app_indicator_set_icon_full: assertion 'IS_APP_INDICATOR (self)' failed

mikeperalta1 avatar Feb 04 '21 07:02 mikeperalta1

My apologies. The issue I reported happens only when building from the latest 1.4 tag. When I switched to 1.3.1 (Ubuntu repos), the tray icon works.

mikeperalta1 avatar Feb 04 '21 07:02 mikeperalta1

My apologies. The issue I reported happens only when building from the latest 1.4 tag. When I switched to 1.3.1 (Ubuntu repos), the tray icon works.

Hi Mike, For the icon to appear when building from source, you have to also install the build via make install.

bk138 avatar Feb 04 '21 08:02 bk138

Ah derp. I should have guessed that. Thank you again!

mikeperalta1 avatar Feb 04 '21 20:02 mikeperalta1

  • https://stackoverflow.com/questions/3003655/is-there-a-good-way-to-copy-a-gtk-widget
  • https://stackoverflow.com/questions/2645850/how-to-copy-or-duplicate-gtk-widgets?noredirect=1&lq=1

bk138 avatar Jul 02 '21 13:07 bk138

This is more of an excuse not to publish v1.5, moving to v1.6.

bk138 avatar Sep 29 '23 09:09 bk138