Commit graph

97 commits

Author SHA1 Message Date
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
Robert Ancell
7e89c293b0 keyboard: Remove unused CcKeyboardOption. 2020-12-11 18:38:04 +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
Ian Douglas Scott
44959e0049 keyboard: remove some dead code 2020-06-29 00:19:54 +00:00
Robert Ancell
1862ec50e4 keyboard: Connect signals with g_signal_connect_object in swapped form 2020-03-30 16:18:49 +13:00
Robert Ancell
a90e13f12c keyboard: Use g_auto for variables 2018-05-29 10:35:14 +12:00
Georges Basile Stavracas Neto
aba1647bea keyboard: Silence initialization warning
This field is always initialized properly before being
used, so let's not initialize it when declaring.
2018-03-16 14:19:43 -03:00
Georges Basile Stavracas Neto
2416b4278d keyboard: Remove unused include 2018-03-16 14:14:11 -03: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
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
69258a91a6 keyboard: Add helper to detect empty keybindings
We'll use this shortly.

https://bugzilla.gnome.org/show_bug.cgi?id=769314
2016-09-08 17:12:17 +02:00
Georges Basile Stavracas Neto
c1529c3417 keyboard: add helper method for user-friendly accelerators
The accelerator formatting method itself is copied from
GtkCellRendererAccel, and will be used throughout the code
to format the accelerators just like they used to be before
moving to the listbox.

https://bugzilla.gnome.org/show_bug.cgi?id=769063
2016-07-29 13:43:47 -03:00
Georges Basile Stavracas Neto
d940d7bb5d keyboard: make it a template class
To allow a much easier porting to the new layout, the keyboard
panel is now a template class. That has various implications on
the code organization:

 - The keyboard-shortcuts.c was responsible for filling the shortcuts.
   Because it relied on the GtkBuilder of the panel, most of its code
   was moved to the CcKeyboardPanel class.
 - The unused code from the keyboard panel class had to be removed in
   order to make it work again.
 - All the hash tables and widgets are now part of the CcKeyboardPanel
   structure.
 - The interface elements have a single entry point.

https://bugzilla.gnome.org/show_bug.cgi?id=769063
2016-07-29 13:43:47 -03:00
Georges Basile Stavracas Neto
dfa01baa9d keyboard: expose structures in header
These structures will be used in future commits when
moving to use a template class.

https://bugzilla.gnome.org/show_bug.cgi?id=769063
2016-07-29 13:43:47 -03:00
Christophe Fergeau
caacec3c86 keyboard: Fix leak when loading sections
This fixes:
==5944== 2,304 bytes in 5 blocks are definitely lost in loss record 15,724 of 16,045
==5944==    at 0x4C2AB9D: realloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==5944==    by 0x1445F0B8: g_realloc (gmem.c:159)
==5944==    by 0x144217CF: g_array_maybe_expand (garray.c:779)
==5944==    by 0x14420C9F: g_array_append_vals (garray.c:418)
==5944==    by 0x48ACFA: append_sections_from_file (keyboard-shortcuts.c:558)
==5944==    by 0x48B4EE: reload_sections (keyboard-shortcuts.c:737)
==5944==    by 0x48EA22: keyboard_shortcuts_init (keyboard-shortcuts.c:2109)
==5944==    by 0x489236: cc_keyboard_panel_constructor (cc-keyboard-panel.c:133)
==5944==    by 0x141C7C3F: g_object_new_with_custom_constructor (gobject.c:1697)
==5944==    by 0x141C7E71: g_object_new_internal (gobject.c:1777)
==5944==    by 0x141C8ADA: g_object_new_valist (gobject.c:2038)
==5944==    by 0x141C7A85: g_object_new (gobject.c:1622)
==5944==    by 0x4547DF: cc_panel_loader_load_by_name (cc-panel-loader.c:213)
==5944==    by 0x44DFCB: activate_panel (cc-window.c:157)
==5944==    by 0x4504D6: cc_window_set_active_panel_from_id (cc-window.c:1036)
==5944==    by 0x44E6A6: item_activated_cb (cc-window.c:280)

https://bugzilla.gnome.org/show_bug.cgi?id=756762
2015-10-19 11:19:17 +02:00
Christophe Fergeau
e235a8a062 keyboard: Fix leak in find_free_settings_path()
==5944== 90 (16 direct, 74 indirect) bytes in 1 blocks are definitely lost in loss record 11,855 of 16,045
==5944==    at 0x4C28C50: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==5944==    by 0x1445EFCC: g_malloc (gmem.c:94)
==5944==    by 0x1445F2AE: g_malloc_n (gmem.c:330)
==5944==    by 0x144982EC: g_variant_dup_strv (gvariant.c:1621)
==5944==    by 0x13EDF251: g_settings_get_strv (gsettings.c:2070)
==5944==    by 0x48D56E: find_free_settings_path (keyboard-shortcuts.c:1651)
==5944==    by 0x48D663: add_custom_shortcut (keyboard-shortcuts.c:1682)
==5944==    by 0x48DB04: add_button_clicked (keyboard-shortcuts.c:1788)

https://bugzilla.gnome.org/show_bug.cgi?id=756762
2015-10-19 11:19:17 +02:00
Bastien Nocera
71de309ff2 keyboard: Fix gtk_tree_model_get_iter_first() retval
https://bugzilla.gnome.org/show_bug.cgi?id=749892
2015-05-27 11:06:02 +02:00
Christophe Fergeau
5f7ee29a44 keyboard: Honor immutable command/name in custom commands
If the gsettings key for the command or name of a custom shortcut is not
writable, the keyboard panel still lets you edit them. This commits
makes the corresponding widgets unsensitive when the gsettings key is
not writable.

https://bugzilla.gnome.org/show_bug.cgi?id=749381
2015-05-15 19:44:00 +02:00
Christophe Fergeau
4257d8723d keyboard: Remove unused CcKeyboardItem::group
The BindingGroupType is stored in the section tree model instead.

https://bugzilla.gnome.org/show_bug.cgi?id=749381
2015-05-15 19:44:00 +02:00
Christophe Fergeau
b442126db1 keyboard: Remove 'gettext_package' handling
It's part of CcKeyboardItem but nothing uses it. It's also parsed
when loading KeyListEntry XML, but never used. The key description is
translated using Keylist::package before gettext_package is assigned.

https://bugzilla.gnome.org/show_bug.cgi?id=749381
2015-05-15 19:44:00 +02:00
Rui Matos
8ea40157b6 keyboard: Add proper casts to silence compiler warnings 2015-02-17 14:55:43 +01:00
Marcus Karlsson
fe9fe99439 keyboard: custom shortcut should require name and command
It is possible to press the Add button in the custom shortcut dialog
when the name and command fields are empty. Disable the button by
default, and only enable it when the name and command is non-empty.

https://bugzilla.gnome.org/show_bug.cgi?id=739647
2015-02-10 13:50:17 +01:00
Bastien Nocera
72cd2e69e1 keyboard: Add translator comments to new feature
Conflict resolution and automatic "Shift" assignment need some
examples for translators to do their work.

https://bugzilla.gnome.org/show_bug.cgi?id=736336
2014-09-09 17:07:07 +02:00
Bastien Nocera
439eb22ca1 keyboard: Fix a crash if the WM changes (or restarts)
By stopping watching for WM changes when leaving the shortcuts panel.

 #0 reload_sections
 #1 wm_window_event_filter
 #2 gdk_event_apply_filters at gdkeventsource.c:81
 #3 gdk_event_source_translate_event at gdkeventsource.c:195
 #4 _gdk_x11_display_queue_events at gdkeventsource.c:338
 #5 gdk_display_get_event at gdkdisplay.c:313
 #10 g_main_context_iteration at gmain.c:3766
 #11 g_application_run at gapplication.c:1623

See https://bugzilla.redhat.com/show_bug.cgi?id=1094480

https://bugzilla.gnome.org/show_bug.cgi?id=736117
2014-09-05 14:15:59 +02:00
Christophe Fergeau
2dbcb26f16 keyboard: Use NULL rather than "" to disable keybindings
When disabling a keybinding, we set its value to { "", NULL } in gsettings
(bindings are stored as arrays of strings).
However, when a binding is disabled by default, its value is set to {
NULL }, not to the empty string.

The use of "" dates back to gconf where I think NULL was not a valid
value. Now that we have switched to gsettings, we can use NULL rather
than an artificial "".

https://bugzilla.gnome.org/show_bug.cgi?id=732383
2014-08-17 20:16:27 +02:00
Christophe Fergeau
ba9a8bc8ff keyboard: Add support for hidden keybinding XML data
If a KeyListEntry has a hidden="true" attribute, then the corresponding
binding information will be loaded as usual, but the binding won't be
displayed in the user interface.

This is useful as the keyboard panel will take into account hidden
keybindings when detecting conflicting shortcuts, or to suggest to set a
reverse shortcut.

For now, this will be used for the various reverse mutter keybindings
({switch,cycle}.*-backward) as they should not be shown in the UI, but
we still want the keyboard panel to know about them.

https://bugzilla.gnome.org/show_bug.cgi?id=731618
2014-08-17 20:16:27 +02:00
Christophe Fergeau
5147cf2502 keyboard: Suggest to automatically set reverse bindings
Since we now know when a binding has a 'reverse' binding, we can now
suggest to update the 'reverse' shortcut when the user set a shortcut
for one of them.

https://bugzilla.gnome.org/show_bug.cgi?id=731618
2014-08-17 20:16:26 +02:00
Christophe Fergeau
f7c095bfe2 keyboard: Parse 'reverse' and 'is-reversed'
This commit adds support for 'reverse' and 'is-reversed' attributes when
parsing the KeyListEntry XML node.

https://bugzilla.gnome.org/show_bug.cgi?id=731618
2014-08-17 20:16:26 +02:00
Christophe Fergeau
10fd199b02 keyboard: Split accel_edit_callback
This function is getting a bit big, and the next commits will add more
code to it.

https://bugzilla.gnome.org/show_bug.cgi?id=731618
2014-08-17 20:16:26 +02:00
Kalev Lember
c5c870a558 keyboard: Port shortcuts tab to GtkGrid
https://bugzilla.gnome.org/show_bug.cgi?id=709057
2014-08-15 14:45:31 +02:00
Matthias Clasen
cd498a06b3 keyboard: drop hard X dependency
The code to listen for window manager changes only makes sense under
X, so don't use it under Wayland. In that case, we can just assume
that we are under GNOME shell when we find a wayland display.

https://bugzilla.gnome.org/show_bug.cgi?id=728679
2014-04-22 17:28:04 -04:00
Daniel Mustieles
2c5951819d Updated FSF's address 2014-01-29 11:27:38 +01:00
Rui Matos
f444c7b28c keyboard: Don't leak a dialog
https://bugzilla.gnome.org/show_bug.cgi?id=708286
2013-10-01 10:05:02 +02:00
Changwoo Ryu
4888729aae keyboard: Allow input of Hangul and Modifier+space shortcuts
These keyboard switching key combinations had been rejected because
using them as shortcuts might prevent users from inputting text. But
now the input source switching keys are configured and processed in
GNOME. So the shortcut settings should allow these key combinations.

https://bugzilla.gnome.org/show_bug.cgi?id=693395
2013-04-22 13:25:19 +09:00
Stéphane Démurget
0e7192e676 keyboard: Improve shortcuts tab keynav
The default focus traversal order inside the shortcuts tab was: the
shortcuts treeview, the section treeview and the shortcuts toolbar.

We set a focus cycle chain to swap the treeviews order for the keynav to
be more natural.

https://bugzilla.gnome.org/show_bug.cgi?id=690387
2012-12-18 11:32:19 +01:00
Bastien Nocera
f94aeb2b02 keyboard: Add support for msgctxt in keybindings
Unfortunately, this means duplicating the description attribute
to the text inside the KeyListEntry element, and marking the
KeyListEntry element as translatable by prepending "_".

<KeyListEntry
	name="search"
	_description="Search"/>
becomes:
<_KeyListEntry
	name="search"
	description="Search"
	msgctxt="keybinding">
		Search
</_KeyListEntry>

https://bugzilla.gnome.org/show_bug.cgi?id=689623
2012-12-06 10:08:14 +01:00
Bastien Nocera
2def485526 keyboard: Ensure the dir name shown matches the XDG Pictures dir
If the Pictures directory was renamed, or the directory name doesn't
match the current language, the dir name would have been wrong.

Enable translator to leave a space for the directory name in their
translation.

https://bugzilla.gnome.org/show_bug.cgi?id=685605
2012-10-10 18:55:53 +02:00
Bastien Nocera
22e31eb3f7 keyboard: Add ability to switch to a shortcuts section
With some new API.

https://bugzilla.gnome.org/show_bug.cgi?id=684280
2012-09-19 00:29:31 +02:00
Bastien Nocera
968618ef8b keyboard: Add unique IDs for each shortcuts section
Rather than relying on comparison of translated strings.

https://bugzilla.gnome.org/show_bug.cgi?id=684280
2012-09-19 00:29:31 +02:00
Rui Matos
978ab40f3e keyboard: Add common XKB options to the Typing shortcuts section
Both the compose key and the 3rd level chooser are common and useful
enough to expose in the control center.

Since these shortcuts are a small pre-defined set of only modifier
keys we present them in combo cell renderers.

https://bugzilla.gnome.org/show_bug.cgi?id=682069
2012-08-20 18:51:39 +02:00
Rui Matos
a24f221eeb keyboard: Introduce a BINDING_GROUP_SEPARATOR type for the separator
This way we can control the shortcut section separator position in
case we introduce other types.

https://bugzilla.gnome.org/show_bug.cgi?id=682069
2012-08-20 18:51:39 +02:00
Rui Matos
f5502645ff keyboard: Remove unused shortcut treeview sorting code
Since the shortcut treeview doesn't have visible headers the sorting
code isn't needed.

https://bugzilla.gnome.org/show_bug.cgi?id=681794
2012-08-18 18:37:25 +01:00
Rui Matos
7bce5758c8 keyboard: Fix adding the section separator after the first time
The separator would only get added the first time the keyboard panel
was opened.

https://bugzilla.gnome.org/show_bug.cgi?id=681788
2012-08-18 18:36:45 +01:00
Rui Matos
0651abd7fb keyboard: Plug a memory leak
https://bugzilla.gnome.org/show_bug.cgi?id=681787
2012-08-18 18:20:15 +01:00
Rui Matos
13b64e0486 keyboard: Plug a GSettings object leak
Also, rename the variable holding it since there are other 'settings'
variables in the same file.

https://bugzilla.gnome.org/show_bug.cgi?id=679328
2012-07-03 16:56:47 +02:00
Bastien Nocera
be88bc1fd3 keyboard: Shift+unmodified key isn't good enough
And it stops upper-case unmodified (or lightly modified) keys from
being captured and unusable for other purposes.
2012-02-19 16:12:30 +01:00
Bastien Nocera
3d3f949f37 keyboard: Remove unused "block_accels" work-around 2012-02-19 16:06:39 +01:00
Bastien Nocera
0965294afd keyboard: Make clicking on description edit the shortcut
As it used it, and broke when we moved to GNOME 3.

https://bugzilla.gnome.org/show_bug.cgi?id=661527
2012-02-18 16:27:29 +01:00
Bastien Nocera
cad6f350ca keyboard: Don't set the "text" property
It won't be used, we're using a function to set the text a line below.
2012-02-14 19:37:53 +00:00