[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Commands depending on active window?
From: |
philippe . brochard |
Subject: |
Re: Commands depending on active window? |
Date: |
Fri, 08 May 2020 17:01:21 +0200 |
egarrulo <address@hidden> writes:
> Hello everybody,
>
Hello,
> is it possible to bind different commands to keys, depending on the
> active window? If so, how?
>
Yes this is doable. One way is to use the guile configuration file:
----8<--- xbindkeys.scm
--8<-------------------------------------------------------------
(use-modules (ice-9 popen)
(ice-9 rdelim))
(define (system-out cmd)
(let* ((port (open-input-pipe cmd))
(str (read-line port)))
(close-pipe port)
str))
(define (do-action)
(let* ((focus-window (system-out "xdotool getwindowfocus"))
(focus-name (system-out (string-append "xdotool getwindowname "
focus-window))))
(display focus-window) (newline)
(display focus-name) (newline)
(cond
((string= focus-name "xterm")
(display "xterm\n")
(run-command "xterm"))
((string= focus-name "Image Viewer")
(display "Image Viewer!\n")
(run-command "evince"))
((string= focus-name "Openbox")
(display "Openbox!\n")
(run-command "xeyes")))))
(xbindkey-function '(control a) do-action)
----8<--- xbindkeys.scm
--8<-------------------------------------------------------------
And you run it with xbindkeys -fg xbindkeys.scm
Note: this is very crude since there is no error handling. But the idea is
here.
> Thank you.
>
Hope this helps
Regards,
Philippe