how to catch keystroke in clipman menu?

Sylvain Viart sylvain at opensource-expert.com
Fri Sep 3 14:36:53 CEST 2021


Hi Gaël,

Thanks.

But not sufficient for me to understand.

I did a test with "show" and "hide", I didn't found where I could 
connect on GtkMenuShell's "selection-done" signal. Especially I'm not 
sure "selection-done" will occur, scenario:

open the menu to track unwanted item:

 1. click to open
 2. navigate up down key of with mouse over
 3. hit delete key, the item is removed and menu updated
 4. you can do it for some more item too.
 5. click else where to continue or close the menu, no selection have
    been done.

My commit looks like:

https://gitlab.xfce.org/Sylvain/xfce4-clipman-plugin/-/commit/8e8e3c69ec9d70cf1fc138826e8a778f895ff0bb#9ccec1d9c5b9b6500f958458cfe0b9d1a4ad557e 
<https://gitlab.xfce.org/Sylvain/xfce4-clipman-plugin/-/commit/8e8e3c69ec9d70cf1fc138826e8a778f895ff0bb#9ccec1d9c5b9b6500f958458cfe0b9d1a4ad557e>

There's already a callback on "show":  _clipman_menu_update_list()
I suppose I can connect multiple handler on the same signal, right?

If I remove the hide handler which crashes, and change for DEL key, it 
seems never reached,

+++ b/panel-plugin/menu.c
@@ -637,20 +637,20 @@ clipman_menu_class_init (ClipmanMenuClass *klass)
  static gboolean
  _clipman_menu_keyboard_event (GtkWidget *widget, GdkEventKey *event, 
gpointer data)
  {
-  if (event->keyval == GDK_KEY_space)
+  if (event->keyval == GDK_KEY_Delete)
    {
-    printf("SPACE KEY PRESSED!");
+    printf("DEL KEY PRESSED!");
      return TRUE;
    }
    return FALSE;
  }

but it is connected, and putting a gdb break point in a keyboard 
handler, has interesting result, the keyboard nor the mouse works 
anymore....

Do gtk knows that my handler is expecting GdkEventKey *event data, 
automatically?
I mean, the prototype of _clipman_menu_update_list() is:

static void _clipman_menu_update_list (ClipmanMenu *menu)

I read that keyboard handler must return bool, so signaling if they 
decided to grab the keystroke or not...

To be continued,
Regards,
Sylvain.

On 03/09/2021 10:49, Gaël Bonithon wrote:
> You can just connect `my_keypress_function()` when the menu is shown 
> (GtkWidget's "show" signal), then, when a key is pressed, you look at 
> which key it is, which menu item is active, and act (or not) accordingly.
>
> No need to bother with what you say in the first part, it should work 
> by itself in this case.
>
> Don't forget to disconnect `my_keypress_function()` when the menu 
> disappears though (GtkMenuShell's "selection-done" signal should be fine).
>
> Cheers,
> Gaël
>
> ‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
> On Thursday, September 2nd, 2021 at 6:20 AM, Sylvain Viart 
> <sylvain at opensource-expert.com> wrote:
>> Hi,
>>
>> I would like to add 2 new key binding in clipman menu, in order to 
>> swap Secure Item as Clear Text, and also to delete any them directly 
>> from menu hitting del key.
>>
>> I lack gtk knowledge, what I found is that:
>>
>> the app seems to do a g_application_register
>>
>> https://docs.gtk.org/gio/method.Application.register.html 
>> <https://docs.gtk.org/gio/method.Application.register.html>
>>
>> but, I think the sole purpose of this is to avoid duplicate running 
>> clipman.
>>
>> I also found, that I should add a keyboard mask somewhere 
>> GDK_KEY_PRESS_MASK
>>
>> https://stackoverflow.com/questions/44098084/how-do-i-handle-keyboard-events-in-gtk3 
>> <https://stackoverflow.com/questions/44098084/how-do-i-handle-keyboard-events-in-gtk3>
>>
>> may be their in panel_plugin_register() ?
>>
>> https://gitlab.xfce.org/Sylvain/xfce4-clipman-plugin/-/blob/secure_item_dbus/panel-plugin/main-panel-plugin.c#L71 
>> <https://gitlab.xfce.org/Sylvain/xfce4-clipman-plugin/-/blob/secure_item_dbus/panel-plugin/main-panel-plugin.c#L71>
>>
>> Then I may be able to add a callback
>>
>> |g_signal_connect (G_OBJECT (window), "key_press_event", G_CALLBACK 
>> (my_keypress_function), NULL); |
>> to my own keyboard handler, and then dispatch on which keystroke I 
>> receive, right?
>> What about "activate" callback on enter key, should I call them after 
>> I introduce a keyboard handler?
>>
>> If you have code example, I would love to discover how it works. 😁
>>
>> Regards,
>> Sylvain.
>> ||_____________________________________________ 
> Xfce4-dev mailing list
> Xfce4-dev at xfce.org
> https://mail.xfce.org/mailman/listinfo/xfce4-dev


-- 
Sylvain Viart - GNU/Linux Sysadmin/Developer/DevOps - France

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.xfce.org/pipermail/xfce4-dev/attachments/20210903/ffbf060d/attachment.html>


More information about the Xfce4-dev mailing list