Skip to content

Commit

Permalink
Concatenate window name into WM_CLASS
Browse files Browse the repository at this point in the history
If you visit https://github.com/mooz/xkeysnail on Google
Chrome, xkeysnail will report WM_CLASS as follows:
  WM_CLASS 'Google-chrome' | active keymaps = ...

After applying this patch, it will be:
  WM_CLASS 'Google-chrome' (mooz/xkeysnail: Yet another
  keyboard remapping tool for X environment - Google
  Chrome)' | active keymaps = ...

This means we can change the keymaps according to the
window title.  This is especially useful when you want to
change the keymap for each tab of the browser.

This patch, however, forces changes to the user's config.py

If possible, I wanted to add the window title as the second
parameter of the lambda function given to "define_keymap",
but the current xkeysnail doesn't support it.

It looks like there's a change that adds a device name to
the second parameter, but It doesn't seem to be working
well.
  • Loading branch information
yoshinari-nomura committed Dec 27, 2020
1 parent bf3c93b commit 2a74e00
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion xkeysnail/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ def get_active_window_wm_class(display=Xlib.display.Display()):
"""Get active window's WM_CLASS"""
current_window = display.get_input_focus().focus
pair = get_class_name(current_window)
wmname = get_window_name(current_window, display)
if pair:
# (process name, class name)
return str(pair[1])
return str(pair[1]) + ' (' + str(wmname) + ')'
else:
return ""

Expand All @@ -40,6 +41,22 @@ def get_class_name(window):
except:
return None

def get_window_name(window, display):
"""Get window's name (recursively checks parents)"""
try:
wmname = window.get_full_text_property(
display.intern_atom('_NET_WM_NAME'),
display.get_atom('UTF8_STRING'))

if (wmname is None):
parent_window = window.query_tree().parent
if parent_window:
return get_window_name(parent_window, display)
return None
return wmname
except:
return None

# ============================================================ #


Expand Down

0 comments on commit 2a74e00

Please sign in to comment.