Commit Graph

86 Commits (3fe8e003566079c454cdbcd433c59aa8a3669091)

Author SHA1 Message Date
Michael Stapelberg 7b502cf44c Fix memleak in translate_keysyms 2015-10-19 18:53:59 +02:00
Ingo Bürk 82dc747396 Make pango markup in mode names optional with a flag.
This introduces the flag "--pango" on the mode config directive to
explicitly enable pango markup for mode names. Not setting this will
cause the mode name to be rendered as is.
This fixes a regression in 4.11 where mode names containing characters
such as '<' would break user's configs as they didn't escape these
characters.

fixes #1992
2015-10-13 09:23:30 +02:00
Michael Stapelberg d24964ff6a Use sasprintf() 2015-10-11 20:42:52 +02:00
Michael Stapelberg 321bba224a Bugfix: add keymap fall back (_XKB_RULES_NAMES, then defaults)
fixes #1983
2015-10-11 20:24:16 +02:00
hwangcc23 fc48a297ed Check duplicated bindings after translating keysym
1). See the issue #1926. For example, the second keybinding is not detected as a duplicate:
        bindcode Mod4+24 sticky toggle
        bindsym Mod4+q focus parent
2). To fix it, check duplicated bindings when translating the keysym to keycodes.
2015-10-02 22:09:53 +08:00
Michael Stapelberg bbefa2a16c Fix “precisely 1 group” error message
fixes #1897
2015-09-05 14:32:58 +02:00
Michael Stapelberg b68a400abf Bugfix: sort bindings, re-ordering once is not enough.
Reordering once (as we did it before this commit) would only sort the
bindings by the _first_ bit of their event_state_mask, but we need to
sort them by _all_ bits of their event_state_mask.

fixes #1870
2015-08-28 09:30:28 +02:00
Michael Stapelberg cbdf1ac8b6 bindings: invert shift bit, don’t just remove it
Before this commit, we only made the transformation of C → c, with this
commit we’re considering both c → C and C → c.

fixes #1870
2015-08-28 09:09:31 +02:00
Michael Stapelberg ea514eb3d4 fix missing clang-format of amended commit 2015-08-26 10:01:14 +02:00
Michael Stapelberg bf3cd41b5d Use libxkbcommon for translating keysyms, support all XKB groups.
fixes #1835

This commit improves the translation of keysyms to keycodes by loading
keymaps using libxkbcommon-x11 and using libxkbcommon for figuring out
the keymap, depending on each keybinding’s modifiers. This way, the
upper layers of complex layouts are now usable with i3’s bindsym
directive, such as de_neo’s layer 3 and higher.

Furthermore, the commit generalizes the handling of different XKB
groups. We formerly had support only for two separate groups, the
default group 1, and group 2. While Mode_switch is only one way to
switch to group 2, we called the binding option Mode_switch. With this
commit, the new names Group1, Group2 (an alias for Mode_switch), Group3
and Group4 are introduced for configuring bindings. This is only useful
for advanced keyboard layouts, such as people loading two keyboard
layouts and switching between them (us, ru seems to be a popular
combination).

When grabbing keys, one can only specify the modifier mask, but not an
XKB state mask (or value), so we still dynamically unbind and re-bind
keys whenever the XKB group changes.

The commit was manually tested using the following i3 config:

    bindsym Group4+n nop heya from group 4
    bindsym Group3+n nop heya from group 3
    bindsym Group2+n nop heya from group 2
    bindsym n nop heya
    bindsym shift+N nop explicit shift binding
    bindsym shift+r nop implicit shift binding
    bindcode Group2+38 nop fallback overwritten in group 2 only
    bindcode 38 nop fallback

…with the following layout:

    setxkbmap -layout "us,ua,ru,de" -variant ",winkeys,,neo" \
      -option "grp:shift_caps_toggle,grp_led:scroll" \
      -model pc104 -rules evdev

By default (xkb group 1, us layout), pressing “n” will result in the
“heya” message appearing. Pressing “a” will result in the “fallback”
message appearing. “j” is not triggered.

By pressing Shift+CapsLock you switch to the next group (xkb group 2, ua
layout). Pressing “a” will result in the “fallback overwritten in group
2 only” message, pressing “n” will still result in “heya”. “j” is not
triggered.

In the next group (xkb group 3, ru layout), pressing “a” will result in
the “fallback” message again, pressing “n” will result in “heya”,
“j” is not triggered.

In the last group (xkb group 4, de_neo layout), pressing “a” will still
result in “fallback”, pressing “n” will result in “heya”, pressing “j”
will result in “heya from group 4”.

Pressing shift+n results in “explicit shift binding”, pressing shift+r
results in “implicit shift binding”. This ensures that keysym
translation falls back to looking at non-shift keys (“r” can be used
instead of ”R”) and that the order of keybindings doesn’t play a role
(“bindsym n” does not override “bindsym shift+n”, even though it’s
specified earlier in the config).

The fallback behavior ensures use-cases such as ticket #1775 are still
covered.

Only binding keys when the X server is in the corresponding XKB group
ensures use-cases such as ticket #585 are still covered.
2015-08-26 09:56:42 +02:00
Michael Stapelberg 0fb784f5cb Translate bindsym bindings upon ISO_Next_Group
With commit c738b2e454 we changed i3 so
that the default keybindings can be used when ISO_Next_Group is enabled,
but bindings which explicitly use Mode_switch have precedence. This
behavior required the use of bindcode instead of bindsym.

With this commit, when switching from group 1 to group 2 using
ISO_Next_Group, i3 will re-translate all keybindings (looking at column
2/3, regardless of whether the keybinding itself specifies Mode_switch)
and re-grab them.

That way, the keybinding “bindsym $mod+x nop foo” will work when
pressing $mod+x without Mode_switch and when pressing the corresponding
$mod+x (different key) with Mode_switch. A binding such as “bindsym
Mode_switch+$mod+x nop bar” will still have precedence.

The intention here is to make bindsym keybindings work well with dual
keyboard layouts (such as {dvorak, us} or {us, ru}), so that users can
switch between groups and still have their (logical) keybindings behave
the same way.

fixes #1775
2015-08-06 09:32:22 +02:00
shdown c85d16faa4 Use safe wrappers wherever possible 2015-08-03 12:50:50 +03:00
shdown bc52fae15c libi3: change scalloc() signature to match calloc() 2015-08-03 12:50:13 +03:00
hwangcc23 478dc5dc38 Fix TODO by replacing atoi by strtol
Fix TODO in bindings.c.
There is no problem to use atoi here since either keycode 0 or button0 is invalid.
But strtol is more flexible and is recommanded for conversion.
2015-06-30 22:22:56 +08:00
Tony Crisci 5c32de43c0 Bugfix: serialize con_id with %p in run_binding()
%p is equivalent to either %x or %lx, depending on the pointer size of the
platform. Before this commit, we always used %d, which has the same behavior
on Linux, but is not automatically expanded to %ld on e.g. FreeBSD.

fixes #1661
2015-04-25 20:05:55 -04:00
Deiz 884214f14f Update copyright notices and get rid of ranges
The script used to make these changes can be found at:

   https://gist.github.com/Deiz/32322020f76d23e2bf8f
2015-04-20 17:50:21 -04:00
Deiz ce48d5c5d7 Add a --border flag to enable mouse binds to trigger on border click 2015-04-02 16:24:05 -04:00
Michael Stapelberg 7340a3e642 Fix bindings using Mode_switch
fixes #1518
2015-03-07 14:52:32 +01:00
Steven McDonald 1ab76fb05a Fix key bindings on big-endian platforms
input_code is a uint16_t, but xcb_keycode_t is uint8_t, meaning that
only the first byte of input_code is inspected by memmem. On
little-endian platforms, this code would have worked by accident, since
the first byte of input_code represents the 8 least significant bits.
However, on big-endian platforms the first byte is the 8 most
significant bits, which means memmem is scanning bind->translated_to
for the wrong keycode (probably 0).

In order to work correctly on big-endian and little-endian platforms,
simply typecast input_code to an xcb_keycode_t and pass that to memmem.

The observed behaviour associated with this bug is that key bindings
don't work at all. This patch has been tested on an iBook G4 running
OpenBSD -current, and key bindings work properly with this fix applied.
2015-03-01 21:07:03 +11:00
Tony Crisci 74b69d6d02 Add mouse binding pointer position configuration
Add the `--whole-window` switch for mouse bindings. This switch controls
what part of the container the pointer must be over to trigger a mouse
binding. The default is to only trigger mouse bindings over the
titlebars. With this switch, a mouse binding will be triggered over the
main part of the window as well.

This is a breaking change to the previous behavior, which would trigger
a mouse binding with a modifier over any part of the window.

fixes #1429
2015-01-31 21:29:48 +01:00
Michael Stapelberg ef9b081a3e Bugfix: check if values are non-NULL before copying (Thanks xeen)
fixes #1397
2014-11-18 08:27:53 +01:00
Tony Crisci bb1f857b00 bugfix: copy binding before run
Copy the binding struct before running it and use this copy to emit the
binding event.

This fixes a crash when the command `reload` is used in a binding when
the binding event is emitted.
2014-11-16 23:36:27 +01:00
Tony Crisci fbaf084426 Implement the ipc 'binding' event
The binding event will be triggered when a binding is run as a result of
some a user action. The binding event has the following properties:

change: (str) Currently this will only be "run" but may be expanded in
the future. Included for consistency with other events.

binding: (map) the serialized binding

The "binding" member will have these properties:

input_type: (str) either "keyboard" or "mouse"

input_code: (int) the xcb keycode of the keyboard binding if it was
provided or the mouse button if it is a mouse binding.

symbol: (str) the string representation of the input code

command: (str) the bound command

mods: (list of str) a list of the modifiers that were pressed as string
symbols

fixes #1210
2014-10-03 09:35:37 +02:00
Michael Stapelberg 3f5a0f0024 Switch to xcb-xkb and libxkbcommon
This removes our last dependency on Xlib! :)

(Okay, an Xlib dependency still comes in through other libraries that we
 link against, but it’s not us. Our code is simpler by this change and
 uses one less connection to X11.)
2014-06-21 19:10:37 +02:00
Tony Crisci 0df172fd05 Feature: implement mouse bindings
A configured mouse binding (for example `bindsym button3 kill`) runs
its command when the mouse button is pressed over parts of a container.

If the binding has no modifer, it will only run when the button is
clicked on the window titlebar.

Otherwise if the binding has a modifier, it will run over the titlebar
or any part of the contained window.

fixes #558
2014-06-19 12:28:54 +02:00
Michael Stapelberg 4c06e7a573 clang-format-3.5 **/*.h **/*.c
This should be the last commit that formats a big bunch of files. From
here on, whenever I merge patches, I’ll run clang-format like described
in the title.
2014-06-19 11:20:32 +02:00
Michael Stapelberg 9200094203 format **/*.c with clang-format-3.5
This has multiple effects:

1) The i3 codebase is now consistently formatted. clang-format uncovered
   plenty of places where inconsistent code made it into our code base.

2) When writing code, you don’t need to think or worry about our coding
   style. Write it in yours, then run clang-format-3.5

3) When submitting patches, we don’t need to argue about coding style.

The basic idea is that we don’t want to care about _how_ we write the
code, but _what_ it does :). The coding style that we use is defined in
the .clang-format config file and is based on the google style, but
adapted in such a way that the number of modifications to the i3 code
base is minimal.
2014-06-15 19:07:02 +02:00
Tony Crisci 7482a0f642 Add abstraction for running a binding
Add run_binding function to bindings.h.

> Runs the given binding and handles parse errors. Returns a
> CommandResult for running the binding's command. Caller should render
> tree if needs_tree_render is true. Free with command_result_free().
2014-06-01 11:55:01 +02:00
Tony Crisci 5fc1b5d02d Refactor binding accessor
Change the primary binding accessor to `get_binding_from_xcb_event`.

This function gets a binding from a generic xcb event of type KeyPress,
KeyRelease, ButtonPress, or ButtonRelease by determining the input type
(keyboard or mouse), the modifiers pressed from the filtered event
`state`, managing the proper fall back in case mode switch is enabled,
and finally querying the bindings for a binding that matches the event.

The logic of querying keyboard bindings is not intended to be altered by
this change.

The general accessor has been slightly modified to work with mouse
bindings and made private because it is only used in bindings.c
2014-05-03 15:34:33 +02:00
Tony Crisci 3171d7ebe5 Implement bindsym mouse configuration
If a `bindsym` config directive specifies a symbol beginning with
"button", the binding will be given the type B_MOUSE for the indicated
button number.

Example:

bindsym $mod+button2 exec echo 'button two'

This will be interpreted as having input code (now `keycode`) 2 and type
B_MOUSE.

The mechanism to find and run mouse bindings on mouse events is not
implemented.
2014-04-30 09:18:53 +02:00
Tony Crisci 02ff10aadb Move check_for_duplicate_bindings to bindings.[ch]
Additionally add a check for the same input_type (mouse or keyboard).
Bindings with different input types cannot be duplicates.
2014-04-26 12:10:33 +02:00
Tony Crisci 702906d0cf Move switch_mode to bindings.[ch] 2014-04-15 17:46:59 +02:00
Tony Crisci c5df093f5d Move translate_keysyms to bindings.[ch]
Additionally add a check so the function only handles bindings of type
B_KEYBOARD to prepare for the new bindmouse feature.
2014-03-15 17:59:57 +01:00
Tony Crisci 3d6d0c134c Move keyboard binding accessor to bindings.[ch]
Rename `get_binding` to `get_keyboard_binding` and ensure that this
function only accesses bindings of type B_KEYBOARD. Other types of
bindings (e.g. mouse bindings) will be accessed by a different function.
2014-02-26 22:26:05 +01:00
Tony Crisci 48ec79ca02 Move grab_all_keys to bindings.[ch]
Also add checks for binding input_type to filter bindings that are not
keyboard bindings.
2014-02-15 12:55:38 +01:00
Tony Crisci d24d8baeb5 Abstract binding configuration to bindings.[ch]
Create files bindings.[ch] to contain functions for configuring,
finding, and running bindings.

Use the new function `configure_binding` for binding configuration. This
function adds a binding from config parameters.

Export the function `modifiers_from_str` from config_directives.h.

This change is made in preparation for the new bindmouse functionality.
2014-01-28 08:21:21 +01:00