Feature request: hook for running script each time the Guake window become visible
Guake is running well here on Ubuntu 16.04 except for little thing: I use an international keyboard layout in the desktop environment but for the terminal I want to use the US keyboard. I have made the layouts available and can switch between them by a key combination. However, I have to do this anew each time Guake becomes visible. For some reason the layout is always reset to the standard one. That becomes tiresome quite soon. So I was wondering if there was a way to issue a script for each tab every time that Guake becomes visible. I have tried the startup script option but of course that script is only run once and does not help much in my case. Also, I toyed around with the idea of running 'guake -s $TAB -e' for each tab but that executes the command directly in the shell which is quite intrusive. Toggling the visibility ten times would clutter each tab with ten identical calls to a script. Maybe even simpler: would it be possible to select the keyboard layout in the settings? Cheers!
If you feel motivated, you can add this feature in settings panel :) should not be that hard, just finding the right API from gtk to do so in Python :)
Thanks for the encouragement but I most likely would not be able to do that because I am not much of a programmer and do not have any over-sight in the source code of Guake. Furthermore, I have come to suspect that an additional hook would not solve my problem that easily. I think the problem itself ought to be addressed for which I shall create an error report of its own. For reference: #796
@sm8ps I think I can implement this
+1
That sounds great, @mouseratti! Let me know if I can help testing.
@Stibbons can you tell me which libs I should install to open .glade files with glade3?
I'm trying to do it, but getting such error message:
(glade:21198): GladeUI-WARNING **: Couldnt recognize GtkBuilder xml, skipping guake.git/data/prefs.glade
Google says, that glade3 must work with old .glade files, but I can not do that..
I use glade2 editor
@sm8ps what command would you like to exec on show terminal window? I've written some code and want to test it now
Thanks for your initiative, @mouseratti! I would like to have the following command run:
gsettings set org.gnome.desktop.input-sources current 1
This switches the keyboard layout on Ubuntu 16.04 with Unity, cf. some kind of reference on askubuntu.com. If I may add a wish, it would be nice if the command did not run in the terminal itself, i.e. by launching it on the command line but in the background. For otherwise it would clutter the terminal window everytime it is opened and it probably would not work if the command line were not blank but contained an unfinished entry. Looking forward to your code!
@sm8ps can you test this feature from my branch? I have added new tab into settings, "Hooks". You can set hook on "show" main window event and check it execution.
#867 is almost finished
Thanks a lot! I finally managed to compile and install. However, I do not see any tab named "Hooks" (cf. attached screen shot). Could it be because I am using a localized version? I did purge the previous version from the Ubuntu repositories. What can I do?
Screenshot:

@sm8ps which version are you running? Have you started guake from my branch issue-793, from commit c77b579 or you just updated guake from your operating system packages repository?
@mouseratti: Forgot to chose the right branch from your Git repo. Sorry, I don't have much experience with software development. Will try again tonight or -morrow and get back.
OK, got it running. Thanks for your patience!
The hooked file is executed, indeed. However it does not totally work as expected by itself. Sometimes the keyboard layout is switched and sometimes not. After some tinkering, I found out that adding "sleep 0.1" at the beginning of the script makes it run in a stable fashion. So with this additional tweak my request is fulfilled even though it is not quite Xmas yet. :) Thanks a lot!
I can only guess why the time-out is necessary but I wonder if it would not be a good idea to add such a tiny time-out to the hook itself (I propose 0.2 to be on the safe side) so as to prevent issues that would be hard to track for the end user. What do you think?
@sm8ps can you show a text of your hook script?
stefan@sp1:~$ ll guakerc.sh
-rwxrwxr-x 1 stefan stefan 238 Dez 11 15:14 guakerc.sh*
stefan@sp1:~$ cat guakerc.sh
#!/bin/bash
sleep 0.1
echo
echo 'Guake hook'
echo 'was:' $(gsettings get org.gnome.desktop.input-sources current)
gsettings set org.gnome.desktop.input-sources current 1
echo 'is:' $(gsettings get org.gnome.desktop.input-sources current)
The echoes were put in for testing when launching Guake from a terminal.
I disabled timeout in your script. Here is my result:
DEBUG:guake.guake_app:hook on event show has been executed
DEBUG:guake.guake_app:Received window state event: <flags GDK_WINDOW_STATE_WITHDRAWN | GDK_WINDOW_STATE_STICKY | GDK_WINDOW_STATE_ABOVE of type GdkWindowState>
DEBUG:guake.guake_app:Received window state event: <flags GDK_WINDOW_STATE_STICKY | GDK_WINDOW_STATE_ABOVE of type GdkWindowState>
Guake hook
org.gnome.desktop.input-sources was: uint32 2
DEBUG:guake.guake_app:Received window state event: <flags GDK_WINDOW_STATE_ABOVE of type GdkWindowState>
DEBUG:guake.guake_app:Received window state event: <flags GDK_WINDOW_STATE_STICKY | GDK_WINDOW_STATE_ABOVE of type GdkWindowState>
DEBUG:guake.guake_app:Received window state event: <flags GDK_WINDOW_STATE_ABOVE of type GdkWindowState>
DEBUG:guake.guake_app:Received window state event: <flags GDK_WINDOW_STATE_STICKY | GDK_WINDOW_STATE_ABOVE of type GdkWindowState>
org.gnome.desktop.input-sources is: uint32 1
It looks working for me without any timeouts. Can you show your log output?
I did not find any switch for activating debugging messages but here is the output when launching Guake from a terminal. It shows the spurious behavior.
INFO:guake.guake_app:Logging configuration complete
/usr/local/lib/python2.7/dist-packages/guake/guake_app.py:866: GtkWarning: IA__gtk_window_set_type_hint: assertion '!gtk_widget_get_mapped (GTK_WIDGET (window))' failed
self.window.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DOCK)
/usr/local/lib/python2.7/dist-packages/guake/guake_app.py:867: GtkWarning: IA__gtk_window_set_type_hint: assertion '!gtk_widget_get_mapped (GTK_WIDGET (window))' failed
self.window.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_NORMAL)
Guake hook
was: uint32 1
is: uint32 0
Guake hook
was: uint32 1
is: uint32 1
Guake hook
was: uint32 1
is: uint32 1
Guake hook
was: uint32 1
is: uint32 0
Guake hook
was: uint32 1
is: uint32 1
I tried opening the Guake window either by my keyboard shortcut (F4) as well as by clicking the "show"-entry in the Guake menu with identical behavior.