Commit graph

64 commits

Author SHA1 Message Date
Brian Ashworth 3952d4f4f3 input/keyboard: respect solo repeat_{rate,delay}
If `repeat_rate` or `repeat_delay` is set without the other being set,
the default was being used for both. This changes the logic to respect
the value given and use the default for the other when only one is set.
2019-02-10 18:45:02 +01:00
Brian Ashworth f5190d1f79 bar_cmd_modifier: add support for none
sway-bar(5) documents `modifier none`, which comes from i3. This
implements the functionality for `modifier none` since it was not
previously implemented. The bar modifier toggles visibility of the bar
when the bar mode is set to hide. When the bar modifier is set to
`none`, the ability to toggle visibility of the bar will be disabled.
2019-02-08 16:02:45 +01:00
M Stoeckl d7ff776552 Move sway-specific functions in common/util.c into sway/
Modifier handling functions were moved into sway/input/keyboard.c;
opposite_direction for enum wlr_direction into sway/tree/output.c;
and get_parent_pid into sway/tree/root.c .
2019-01-21 12:39:16 -05:00
M Stoeckl 1211a81aad Replace wlr_log with sway_log
This commit mostly duplicates the wlr_log functions, although
with a sway_* prefix. (This is very similar to PR #2009.)
However, the logging function no longer needs to be replaceable,
so sway_log_init's second argument is used to set the exit
callback for sway_abort.

wlr_log_init is still invoked in sway/main.c

This commit makes it easier to remove the wlroots dependency for
the helper programs swaymsg, swaybg, swaybar, and swaynag.
2019-01-21 12:59:42 +01:00
Brian Ashworth 2573606b60 Disarm key repeat on reload
When resetting the keyboard during reload, disarm the key repeat on all
keyboards since the bindings (and possibly keyboard) will be freed before
the key repeat can go off.
2019-01-14 20:15:23 +01:00
Brian Ashworth 1feb2ce064 keyboard: update repeat timer before execution
Since the keyboard can be destroyed by executing a binding (reloading
with a different seat attachment config), update the repeat timer before
executing the binding.
2019-01-09 01:07:29 -05:00
Franklin "Snaipe" Mathieu f8e83ee20a binding: match single-key bindings if no multi-key binding matched
This makes bindings more snappy when the user is typing faster than
his keycaps are releasing.

Signed-off-by: Franklin "Snaipe" Mathieu <me@snai.pe>
2018-10-29 13:04:19 +00:00
Ryan Dwyer c006717910 Minor refactor of input manager
The input manager is a singleton object. Passing the sway_input_manager
argument to each of its functions is unnecessary, while removing the
argument makes it obvious to the caller that it's a singleton. This
patch removes the argument and makes the input manager use server.input
instead.

On a similar note:

* sway_input_manager.server is removed in favour of using the server
global.
* seat.input is removed because it can get it from server.input.

Due to a circular dependency, creating seat0 is now done directly in
server_init rather than in input_manager_create. This is because
creating seats must be done after server.input is set.

Lastly, it now stores the default seat name using a constant and removes
a second reference to seat0 (in input_manager_get_default_seat).
2018-10-20 13:11:43 +10:00
Brian Ashworth 2e637b7368 cmd_bind{sym,code}: Implement per-device bindings
bindsym --input-device=<identifier> ...
bindcode --input-device=<identifier> ...
2018-10-18 13:42:01 -04:00
Ian Fan 2f1fd80726 swaybar: show hidden bar on key event
Since wayland does not currently allow swaybar to create global
keybinds, this is handled within sway and sent to the bar using a custom
event, so as not to pollute existing events, called bar_state_update.
2018-10-14 13:33:12 +01:00
Ryan Dwyer 88a5e26c6e Remove unneeded variable 2018-10-08 20:40:47 +10:00
Ryan Dwyer 82423991a8 Reload config using idle event
This patch makes it so when you run reload, the actual reloading is
deferred to the next time the event loop becomes idle. This avoids
several use-after-frees and removes the workarounds we have to avoid
them.

When you run reload, we validate the config before creating the idle
event. This is so the reload command will still return an error if there
are validation errors. To allow this, load_main_config has been adjusted
so it doesn't apply the config if validating is true rather than
applying it unconditionally.

This also fixes a memory leak in the reload command where if the config
failed to load, the bar_ids list would not be freed.
2018-10-08 19:28:53 +10:00
Drew DeVault eecebcafc6 Fix #2763 2018-10-04 15:00:18 -04:00
Ryan Dwyer 32c7386b0f Fix management of bindings during reload
seat_execute_command needs to check the flags on `binding_copy`, as
`binding` will be a dangling pointer after a reload command.

handle_keyboard_key needs to set the next_repeat_binding for
non-reloads prior to executing the command in case the binding is
freed by the reload command.
2018-09-06 08:33:00 +10:00
Ryan Dwyer 7797490e9e Deny repeating reload by holding key
Fixes #2568

The binding that gets stored in the keyboard's `repeat_binding` would
get freed on reload, leaving a dangling pointer.

Rather than attempt to unset the keyboard's `repeat_binding` along with
the other bindings, I opted to just not set it for the reload command
because there's no point in reloading repeatedly by holding the binding.
This disables repeat bindings for the reload command.

As we now need to detect whether it's a reload command in two places,
I've added a binding flag to track whether it's a reload or not.
2018-09-04 20:00:04 +10:00
frsfnrrg 8dbbfa5965 Bindings use advised keyboard repeat parameters
Now 'repeat_delay' and 'repeat_rate' control the initial delay
and rate (per second) of repeated binding invocations.

If the repeat delay is zero, binding repetition is disabled.
When the repeat rate is zero, the binding is repeated exactly
once, assuming no other key events intervene.
2018-07-29 19:15:10 -04:00
frsfnrrg e33dfbfa75 Implement key repeat for pressed key bindings
Each sway_keyboard is provided with a wayland timer event source.
When a valid keypress binding has been found, a callback to
handle_keyboard_repeat is set. Any key event will either clear
the callback or (if the new key event is a valid keypress binding)
delay the callback again.
2018-07-29 19:15:02 -04:00
Geoff Greer 30fee94354 Don't enable numlock by default. This fixes an annoying issue where laptop keyboards would have 'numlock mode' enabled, remapping parts of the alphabet to numbers. 2018-07-28 16:22:20 -07:00
ProgAndy 76ece5788b Fix LEDs for configured modifier states 2018-07-25 17:24:45 +02:00
ProgAndy 2166dbe2e4 Implement setting NumLock and CapsLock status
After setting the keymap, try to enable NumLock and disable CapsLock.
This only works if sway has the xkb master state and controls the keyboard.
Prepare configuration settings for later use as well.
2018-07-25 17:24:45 +02:00
frsfnrrg 94dd8823a0 Invoke mouse bindings
The mouse binding logic is inspired/copied from the
keyboard binding logic; we store a sorted list of the
currently pressed buttons, and trigger a binding when
the currently pressed (or just recently pressed, in
the case of a release binding) buttons, as well as
modifiers/container region, match those of a given
binding.

As the code to execute a binding is not very keyboard
specific, keyboard_execute_command is renamed to
seat_execute_command and moved to where the other
binding handling functions are. The call to
transaction_commit_dirty has been lifted out.
2018-07-23 21:38:29 -04:00
frsfnrrg 754372c3de Parse mouse binding options
First, the existing sway_binding structure is given an
enumerated type code. As all flags to bindsym/bindcode
are boolean, a single uint32 is used to hold all flags.
The _BORDER, _CONTENTS, _TITLEBAR flags, when active,
indicate in which part of a container the binding can
trigger; to localize complexity, they do not overlap
with the command line arguments, which center around
_TITLEBAR being set by default.

The keyboard handling code is adjusted for this change,
as is binding_key_compare; note that BINDING_LOCKED
is *not* part of the key portion of the binding.

Next, list of mouse bindings is introduced and cleaned up.

Finally, the binding command parsing code is extended
to handle the case where bindsym is used to describe
a mouse binding rather than a keysym binding; the
difference between the two may be detected as late as
when the first key/button is parsed, or as early as
the first flag.  As bindings can have multiple
keycodes/keysyms/buttons, mixed keysym/button sequences
are prohibited.
2018-07-23 21:14:22 -04:00
Ryan Dwyer a120d4c79f Make focus part of transactions
Rather than maintain copies of the entire focus stack, this PR
transactionises the focus by introducing two new properties to the
container state and using those when rendering.

* `bool focused` means this container has actual focus. Only one
container should have this equalling true in its current state.
* `struct sway_container *focus_inactive_child` points to the immediate
child that was most recently focused (eg. for tabbed and stacked
containers).
2018-07-15 22:08:26 +10:00
emersion 63b4bf5000
Update for swaywm/wlroots#1126 2018-07-09 22:54:30 +01:00
Dominique Martinet 8a771785ad keyboard: free xkb keymap on destroy 2018-07-05 08:13:10 +09:00
Armin Preiml 1eede432fc fix handling key modifiers if not pressed at first
fixes #2169
2018-06-28 15:23:26 +02:00
frsfnrrg ca061ba8bf Fix keyboard shortcut handling inconsistencies
* Ensure that modifier keys are identified even when the next key does
  not produce a keysym. This requires that modifier change tracking
  be done for each sway_shortcut_state.

* Permit regular and --release shortcuts on the same key combination.
  Distinct bindings are identified for press and release cases; note
  that the release binding needs to be identified for both key press
  and key release events.

* Maintain ascending sort order for the shortcut state list, and keep
  track of the number of pressed key ids, for simpler (and hence
  faster) searching of the list of key bindings.

* Move binding duplicate detection into get_active_binding to avoid
  duplicating error messages.
2018-06-12 20:26:57 -04:00
Brian Ashworth 7c810dc344 Make command block implementation generic 2018-06-02 08:07:44 -04:00
frsfnrrg 78b7b46895 Style fix, redundant entry removal, fix extra keysym delete 2018-06-01 18:52:36 -04:00
frsfnrrg 480f0c593c Rename update_shortcut_model to update_shortcut_state 2018-06-01 18:52:36 -04:00
frsfnrrg 83d559dd03 Rename check_shortcut_model to get_active_binding 2018-06-01 18:52:36 -04:00
frsfnrrg c53e4e6cde Style fixed for keyboard.c 2018-06-01 18:52:36 -04:00
frsfnrrg f2fe93d171 Remove almost-always redundant loop in key handling 2018-06-01 18:52:36 -04:00
frsfnrrg a056419ad7 Rewrite shortcut handling code to avoid hardcoded values
The same shortcut algorithm is now used for keycodes,
raw keysyms, and translated keysyms. Pressed keysyms
are now stored in association with the keycodes that
generated them. Modifier keycodes (and associated
keysyms) are identified retroactively by the subsequent
change to the modifier flags.
2018-06-01 18:52:36 -04:00
frsfnrrg a78a5684ea Implement bindsym/bindcode --locked
Adds the --locked flag to bindsym and bindcode commands.

When a keyboard's associated seat has an exclusive client
(i.e, a screenlocker), then bindings are only executed if
they have the locked flag. When there is no such client,
this restriction is lifted.
2018-05-27 13:28:02 -04:00
Mattias Eriksson 8fbafbfab5 Idle handling for dpms/lockscreen et al
Swayidle handles idle events and allows
for dpms and lockscreen handling. It also
handles systemd sleep events, and can
raise a lockscreen on sleep

Fixes #541
2018-05-13 00:30:09 +02:00
Ryan Dwyer 5b30391383 Make key repeat configurable
This creates two input commands for configuring the repeat delay and rate.

Example config:

    input "myidentifier" {
        repeat_delay 250
        repeat_rate 25
    }
2018-04-18 23:19:23 +10:00
Tony Crisci 5e024278a6 Merge branch 'wlroots' into seat-fixes 2018-04-02 13:23:43 -04:00
Tony Crisci 22287b42bf dont copy input config 2018-04-02 13:19:58 -04:00
Drew DeVault b2d871cfe2 Partially implement move command
Works:

- move [container|window] to workspace <name>
    - Note, this should be able to move C_CONTAINER but this is untested
- move [workspace] to output [left|right|up|down|<name>]

Not implemented yet:

- move [left|right|up|down]
- move scratchpad
- move position
2018-04-02 11:12:18 -04:00
Tony Crisci ac8269d536 take seat param for handle_command and rename 2018-02-24 12:50:24 -05:00
Tony Crisci c353e01c85 add kill command 2018-01-20 14:10:11 -05:00
Tony Crisci 2bf76509f8 update for new wlr-keyboard modifiers 2018-01-17 11:47:27 -05:00
Dominique Martinet 67985e9031 sway: change all sway_log to wlr_log 2018-01-05 23:39:46 +01:00
Tony Crisci 8b4eb5d7d1 cleanup bindings 2018-01-04 07:54:14 -05:00
Tony Crisci 50e791cadb binding release 2018-01-04 07:25:52 -05:00
Tony Crisci bd3ca70e3d fix nitpicks 2017-12-29 09:11:15 -05:00
Tony Crisci 62b7ab3959 overwrite old bindings 2017-12-28 18:50:22 -05:00
Tony Crisci 0b8481f41a fix keyboard_execute_bindcode 2017-12-28 16:52:12 -05:00
Tony Crisci 8d567cd062 bindcode 2017-12-28 16:24:23 -05:00