Commit graph

57 commits

Author SHA1 Message Date
Marcos Miller
b5ce4fafcd keyboard: replace 'gtk_widget_hide' and 'gtk_widget_show' 2023-07-03 10:33:39 +00:00
Marcos Miller
e7de7e3941 Keyboard: Align button to create shortcut
The 'Set Shortcut...' button is inside a GtkStack having only one
column, not allowing to expand it.

I removed GtkStack keeping its 'Set Shortcut' child taking up two
columns.

[Issue #2107](https://gitlab.gnome.org/GNOME/gnome-control-center/-/issues/2107)
2023-07-03 10:33:39 +00:00
Robert Ancell
a06914a60c keyboard: Do signal handlers in swapped form 2023-05-30 08:36:22 +00:00
Maksym Hazevych
5b988a6943 Replace all occurrences of 'gtk_widget_hide'
Replace all occurrences of 'gtk_widget_hide(smth)' with
'gtk_widget_set_visible(smth, FALSE)'.
2023-03-29 14:26:55 +13:00
Mohammed Sadiq
f1c09a9277 keyboard: shortcut-editor: Properly escape text
Related #852 #1529
2022-12-05 20:50:15 +00:00
Sebastian Keller
bad61a2229 keyboard: Handle shift shortcut modifier the same way as the shell does
The way shortcuts in mutter/gnome-shell work is that it looks up the
keycode that generates the shortcut keyval at the lowest shift level and
then checks if all the modifiers match. This does not work for shortcuts
that for example include "dollar" to represent "<Shift>4", because on
some keyboards/layout there is a separate dollar key key with its own
keycode. This would be at a lower shift level than "<Shift>4".

By always translating such shortcuts to "<Shift>number", we make sure
the resulting shortcut will work in the shell and is closer to what the
user likely intended the shortcut to be, because numbers are usually
assigned to things that can be enumerated, such as workspaces or
favorite applications.

This also special cases the num-row key on layouts such as AZERTY, where
the number is the shifted keyval, to always prefer the number. Due to
the way the shell interprets these shortcuts, they still work and by
always using numbers they work across different layouts.

This change also fixes that pressing "<Shift><Super>4" was turned into
"<Shift><Super>dollar", which effectively included the "<Shift>" twice.

Fixes: https://gitlab.gnome.org/GNOME/gnome-control-center/-/issues/1528
2022-08-22 12:49:13 +00:00
Sebastian Keller
986a37ff6c keyboard: Split out function to normalize keyval and modifier mask
This will allow it to be tested in a unit test in an upcoming commit.
2022-08-22 12:49:13 +00:00
Victor Toso
8355404ed4 keyboard-shortcut-editor: fix leak of accel string
==31571== 120 bytes in 8 blocks are definitely lost in loss record 17,034 of 19,290
==31571==    at 0x484086F: malloc (vg_replace_malloc.c:380)
==31571==    by 0x4AF77A8: g_malloc (gmem.c:106)
==31571==    by 0x4D9816A: gtk_accelerator_name (gtkaccelgroup.c:1577)
==31571==    by 0x4A82D1: setup_custom_shortcut (cc-keyboard-shortcut-editor.c:364)
==31571==    by 0x4A92DF: cc_keyboard_shortcut_editor_key_press_event (cc-keyboard-shortcut-editor.c:745)
2021-12-17 09:53:41 +01:00
Georges Basile Stavracas Neto
d7e794e7ab keyboard: Port to GTK4
Drop the wm-common insanity.
2021-12-14 22:34:21 -03:00
Ian Douglas Scott
621dd80ab0 keyboard: Do now call g_binding_unbind() finalizing shortcut editor
This errors and is unnecessary because the binding is removed when the
object bound is finalized.
2021-01-11 15:19:36 -08:00
Ian Douglas Scott
fe173f661b keyboard: Do not call gtk_grab_{add,remove} in shortcut editor
For some reason, the ungrab was making the window impossible to interact
with. Without these calls, it seems to work as expected.
2020-12-18 07:55:41 -08:00
Ian Douglas Scott
099426714c keyboard: Fix behavior of "Replace" when adding custom shortcut
In the shortcut editor, the "Replace" button is shown instead of "Set"
or "Add" when there is a collision. But this executes the same code as
"Set", so when adding a shortcut, it doesn't actually work.
2020-09-25 03:17:29 +00:00
Ian Douglas Scott
67cb508802 keyboard: Refactoring of CcKeyboardItem handling of multiple combos
This commit includes all the changes that seem to be necessary for
CcKeyboardItem to be used for dealing with multiple keybindings, without
(yet) changing the user interface to expose this.

The `primary_combo` and `binding` fields of `CcKeyboardItem` are
removed, in favor of the existing `key_combos`. No combination is
"primary", since all of them can now be seen and changed equally.

We treat `CcKeyboardItem.key_combos` as a set, that a combo can be added
to or removed from. Though it continues to be represented as a `GList`,
instead of a `GHashTable`, to preserve ordering.

A lot of the keyboard panel code relied on the assumption that only one
combo can be set for each setting, so this required a variety of
miscellaneous changes.
2020-09-14 17:19:33 +00:00
Yuri Chornoivan
e7050ab6f4 Fix minor typos 2020-07-20 10:38:09 +03:00
Ian Douglas Scott
7244bd997d keyboard: unify standard_edit_box and custom_edit_box
The redundant design here seemed awkward when I was thinking about how
to implement support for displaying multiple conflicts as needed by
https://gitlab.gnome.org/GNOME/gnome-control-center/-/merge_requests/776
and https://gitlab.gnome.org/GNOME/gnome-control-center/-/issues/1041.

This should be more maintainable.
2020-07-01 10:38:30 -07:00
Ian Douglas Scott
34883c0c33 keyboard: fix seat grabbing when setting custom shortcut
The callback `edit_custom_shortcut_button_toggled_cb()` was unused,
presumably a relic of an earlier UI design.
2020-06-29 15:25:27 -07:00
Robert Ancell
ef9b0c7313 keyboard: Replace GtkStack child names with widget references
The child names are easier to break if widgets are changed - this can't be
detected by the compiler.
2020-03-30 01:49:50 +00:00
Robert Ancell
ee4d08ca1d keyboard: Use GTK widget types 2020-03-30 01:49:50 +00:00
Robert Ancell
df71952112 keyboard: Remove markup from translatable strings 2020-01-06 16:57:43 +00:00
Robert Ancell
6fc8e57bdd keyboard: Make .ui filename match the .c filename 2019-09-09 21:58:01 +00:00
Robert Ancell
57975633e6 keyboard: Replace GObject boilerplace with G_DECLARE_TYPE 2018-05-29 15:44:19 +00:00
Robert Ancell
a90e13f12c keyboard: Use g_auto for variables 2018-05-29 10:35:14 +12:00
Bastien Nocera
a1f57ce50a keyboard: Simplify keyboard grab
https://bugzilla.gnome.org/show_bug.cgi?id=793070
2018-02-06 10:42:18 +01:00
Florian Müllner
dccf794897 keyboard: Add dedicated key combo type
We currently store keyval, keycode and mask that make up a particular
key combo separately. However as we want to consider multiple bindings
for a single item, it makes more sense to combine them in a dedicated
struct type.

https://bugzilla.gnome.org/show_bug.cgi?id=673078
2017-07-10 19:29:43 +02:00
Georges Basile Stavracas Neto
dce6fe6add keyboard: Move Remove button to the header bar
According to the mockups [1], the Remove button should
be placed at the start of the header bar. Currently,
however, it is positioned below the custom shortcut edit
button.

Fix that by moving the remove button to the header bar.

[1] https://raw.githubusercontent.com/gnome-design-team/gnome-mockups/master/system-settings/keyboard/keyboard-wires.png

https://bugzilla.gnome.org/show_bug.cgi?id=777846
2017-05-02 07:20:29 -03:00
Georges Basile Stavracas Neto
e601ae74ee keyboard: ensure the "Add" button is insensitive when adding shortcut
After successfully editing a default shortcut (and making sure the
"Set" button is sensitive), if the user clicks the '+' row to create
a new custom shortcut, the "Add" button is sensitive even with all
fields empty.

Fix that by ensuring the "Add" button is always insensitive whenever
we add a custom shortcut.

https://bugzilla.gnome.org/show_bug.cgi?id=777842
2017-02-08 14:15:16 -02:00
Georges Basile Stavracas Neto
c57cadf50b keyboard: make the "Set" and "Add" buttons blue
Per the available mockups [1], the "Set" and "Add" buttons
are the suggested action of the dialog and should be blue.

[1] https://raw.githubusercontent.com/gnome-design-team/gnome-mockups/master/system-settings/keyboard/keyboard-wires.png

https://bugzilla.gnome.org/show_bug.cgi?id=777842
2017-02-08 14:15:16 -02:00
Georges Basile Stavracas Neto
1e13e97556 keyboard: manage shortcut editor state with pages
The current shortcut editor state is managed by setting and
comparing the page name directly, making the code look more
complicated than it should.

Fix this by introducing the concept of pages, and using this
to set and get the current shortcut editor dialog state.

https://bugzilla.gnome.org/show_bug.cgi?id=777845
2017-01-30 13:26:25 -02:00
Georges Basile Stavracas Neto
147a1e814d keyboard: fix editing of custom shortcuts
After introducing the reset button to match the mockups [1], the
shortcut editor dialog had some issues exposed. This is visible
e.g. when the user tries to edit a custom shortcut's name and
the shortcut is disabled.

This happens because we assume there is always a shortcut set.
When we open the dialog to edit a custom shortcut, however, nothing
is actually set, and we end up saving the disabled shortcut when
editing the shortcut's name or command.

Fix that by initializing the shortcut's accelerators when editing a
shortcut, and correcting the logic to validate the shortcut.

[1] https://raw.githubusercontent.com/gnome-design-team/gnome-mockups/master/system-settings/keyboard/keyboard-wires.png

https://bugzilla.gnome.org/show_bug.cgi?id=777845
2017-01-30 13:26:12 -02:00
Georges Basile Stavracas Neto
20f52da5e2 keyboard: switch to the reset button
Per the mockups [1], when editing a custom shortcut, there is
a reset button right after the current shortcut. When there
is no shortcut set, it shows a "Set Shortcut" button instead.
The current UI to edit a shortcut, however, diverges from
the proposed one since we use an "Edit" button instead.

Fix that by swapping the Edit button with a reset button, and
adapt the code to not depend on the edit button anymore.

[1] https://raw.githubusercontent.com/gnome-design-team/gnome-mockups/master/system-settings/keyboard/keyboard-wires.png

https://bugzilla.gnome.org/show_bug.cgi?id=777845
2017-01-30 13:24:33 -02:00
Georges Basile Stavracas Neto
05e03617e1 shortcut-editor: fix headerbar state when adding shortcut
When adding a custom shortcut, the header mode was set to be
only "Cancel". Per mockups, the "Add" button should also be
visible but insensitive.

Fix that by correctly setting the header mode on creation mode.

https://bugzilla.gnome.org/show_bug.cgi?id=777824
2017-01-27 14:20:47 -02:00
Georges Basile Stavracas Neto
4fac9192d8 shortcut-editor: ensure sensitive entries on creation mode
When creating a new shortcut, we currently assume the entries are
sensitive and just show the dialog. This, however, may not be, for
example after previously canceling the editing of a custom shortcut,
leading to a state where the name and command entries are insensitive.

Fix that by always making sure the entries are sensitive when
setting the dialog to creation mode.

https://bugzilla.gnome.org/show_bug.cgi?id=777824
2017-01-27 14:20:47 -02:00
Georges Basile Stavracas Neto
ecf352c1d2 shortcut-editor: untoggle Edit button on cancel
When canceling the editing of a custom shortcut, the "Edit" button
keeps pressed, causing inconsistencies when editing future custom
events.

To reproduce that:
 - Open a custom shortcut and click "Edit"
 - Start typing the new shortcut; the "Cancel" button will appear
 - *Before* completing the new shortcut, click "Cancel"; the dialog will hide
 - Open a custom shortcut again; the "Edit" button is still toggled

Fix that by properly untoggling the Edit button when cancelling
the editing.

https://bugzilla.gnome.org/show_bug.cgi?id=777824
2017-01-27 14:20:47 -02:00
Bastien Nocera
6c598fa9d1 keyboard: Fix capture of Alt+PrintScreen shortcuts
Alt+PrintScreen gives you Alt+SysRq. Repair the key value to match user
expectations instead.

https://bugzilla.gnome.org/show_bug.cgi?id=772050
2016-10-10 18:10:57 +02:00
Bastien Nocera
510d980431 keyboard: Fix shortcut label in RTL languages
https://bugzilla.gnome.org/show_bug.cgi?id=771110
2016-09-09 16:51:36 +02:00
Bastien Nocera
45fb0a4feb keyboard: Normalise Shift and Tab in shortcuts
https://bugzilla.gnome.org/show_bug.cgi?id=771058
2016-09-08 17:38:04 +02:00
Florian Müllner
789639004f keyboard: Remove additional filtering of default mod mask
The mask returned by gtk_accelerator_get_default_mod_mask() should
work without additional filtering, in particular when it is overly
restrictive - a lot of shortcuts use the Super modifier nowadays,
so stop filtering it out.

https://bugzilla.gnome.org/show_bug.cgi?id=771058
2016-09-08 17:38:04 +02:00
Florian Müllner
4beb7cefd4 keyboard: Allow Tab in accels
gtk_accelerator_valid() doesn't accept Tab as keyval, so using it to
check whether a shortcut is valid breaks commonly used shortcuts like
Alt+Tab. Unbreak those by adding a small wrapper that special-cases
Tab-with-modifiers.

https://bugzilla.gnome.org/show_bug.cgi?id=771058
2016-09-08 17:38:04 +02:00
Bastien Nocera
784d8f89de keyboard: Don't apply "Backspace" straight away
Before, when pressing "Backspace" in the editing dialogue, the
keybinding would be changed straight away, *behind* the dialogue, and
the dialogue would still be expecting a new shortcut.

Instead, we should make it behave like other shortcuts, which means
special handling empty shortcuts as valid ones.

https://bugzilla.gnome.org/show_bug.cgi?id=769314
2016-09-08 17:12:17 +02:00
Bastien Nocera
58b175f351 keyboard: Fix grabs not working when showing the dialog
We couldn't override gnome-shell's keybindings without having a working
grab, but the grab was only started when clicking the "edit" button when
editing a custom shortcut, or *after* receiving the first key press event.

To fix that problem, we need to grab the keyboard once we've shown the
dialog itself, but not in the ->map vfunc, otherwise it will block the
dialog from showing up. We set up a short timeout instead. Hopefully
this isn't too fragile.

https://bugzilla.gnome.org/show_bug.cgi?id=769314
2016-09-08 17:12:17 +02:00
Bastien Nocera
141441eb71 keyboard: Don't regrab the keyboard after an event
It was already grabbed if we received the event, so no need to grab it
again.

https://bugzilla.gnome.org/show_bug.cgi?id=769314
2016-09-08 17:12:17 +02:00
Bastien Nocera
6c7746abb3 keyboard: Don't rely on events to grab keyboard
Rather than relying on us being in the middle of processing an event to
grab the keyboard, get the keyboard for the first seat of the display.

https://bugzilla.gnome.org/show_bug.cgi?id=769314
2016-09-08 17:12:17 +02:00
Bastien Nocera
b10a1ac935 keyboard: Don't grab the mouse pointer
In a0a15588, we starting using a separate shortcut editor window, which
was doing its own capture instead of using the GtkCellRendererAccel. But
this started grabbing both keyboard and pointer, making it impossible to
cancel captures using the pointer.

We now only grab keyboard keys, making the pointer usable again.

https://bugzilla.gnome.org/show_bug.cgi?id=769314
2016-09-08 17:12:17 +02:00
Bastien Nocera
b32f58ed00 keyboard: Remove unused variable
grab_device was added in a0a15588 but unused there or since.

https://bugzilla.gnome.org/show_bug.cgi?id=769314
2016-09-08 17:12:17 +02:00
Georges Basile Stavracas Neto
778395f61b shortcut-editor: show custom page while waiting for input
While waiting for keyboard input, as per the new proposed mockup,
the shortcut editor dialog should show a custom page with an icon
that indicates the required action. The current code, however, does
not expose this new customized page.

Fix that by adding this new page and controlling the time when it
shows and hides.

https://bugzilla.gnome.org/show_bug.cgi?id=769314
2016-09-08 17:12:17 +02:00
Georges Basile Stavracas Neto
c5cd32f797 shortcut-editor: use a different page to edit custom shortcuts
When adding a new keyboard shortcut, in accordance to the mockups,
the dialog should present a new page calling for an action from the
user.

This patch adds this page, and adapts the code to show it whenever
the user wants to change the shortcut.

https://bugzilla.gnome.org/show_bug.cgi?id=769314
2016-09-08 17:12:17 +02:00
Georges Basile Stavracas Neto
4db1337664 shortcut-editor: hide editing dialog on Escape
When editing a standard shortcut, the current code only
cancels the editing on Escape, but doesn't hide the
dialog.

Fix that by properly handling the canceling of shortcut
editing and making sure we always hide the dialog on
cancel.

https://bugzilla.gnome.org/show_bug.cgi?id=769314
2016-09-08 17:12:17 +02:00
Georges Basile Stavracas Neto
40ee225385 shortcut-editor: use states to handle headerbar mode
Instead of manually handling every button in the headerbar
individually, using states to switch between modes. It's clearer
and easier to maintain.

This patch adds the headerbar mode handling code, and updates
the current code to use it rather than by updating each individual
button manually.

https://bugzilla.gnome.org/show_bug.cgi?id=769314
2016-09-08 17:12:17 +02:00
Georges Basile Stavracas Neto
472959657b shortcut-editor: add 'Set' button
The Set button will be used to update a standard
shortcut.

This patch adds it to the headerbar.

https://bugzilla.gnome.org/show_bug.cgi?id=769314
2016-09-08 17:12:17 +02:00
Georges Basile Stavracas Neto
5637d573a6 shortcut-editor: update header title message
Instead of showing the shortcut description, show an
action-oriented title, according to the mockups. Precisely,
"Set Shortcut" for standard shortcuts and "Set Custom
Shortcut" for custom shortcuts.

https://bugzilla.gnome.org/show_bug.cgi?id=769314
2016-09-08 17:12:17 +02:00