Line |
Branch |
Exec |
Source |
1 |
|
|
/* cc-keyboard-shortcut-row.c |
2 |
|
|
* |
3 |
|
|
* Copyright (C) 2020 System76, Inc. |
4 |
|
|
* Copyright (C) 2022 Purism SPC. |
5 |
|
|
* |
6 |
|
|
* This program is free software: you can redistribute it and/or modify |
7 |
|
|
* it under the terms of the GNU General Public License as published by |
8 |
|
|
* the Free Software Foundation, either version 2 of the License, or |
9 |
|
|
* (at your option) any later version. |
10 |
|
|
* |
11 |
|
|
* This program is distributed in the hope that it will be useful, |
12 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
|
|
* GNU General Public License for more details. |
15 |
|
|
* |
16 |
|
|
* You should have received a copy of the GNU General Public License |
17 |
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
18 |
|
|
* |
19 |
|
|
* SPDX-License-Identifier: GPL-2.0-or-later |
20 |
|
|
*/ |
21 |
|
|
|
22 |
|
|
#include <glib/gi18n.h> |
23 |
|
|
#include "cc-keyboard-shortcut-row.h" |
24 |
|
|
#include "keyboard-shortcuts.h" |
25 |
|
|
|
26 |
|
|
struct _CcKeyboardShortcutRow |
27 |
|
|
{ |
28 |
|
|
AdwActionRow parent_instance; |
29 |
|
|
|
30 |
|
|
GtkLabel *accelerator_label; |
31 |
|
|
GtkButton *reset_button; |
32 |
|
|
GtkRevealer *reset_revealer; |
33 |
|
|
|
34 |
|
|
CcKeyboardItem *item; |
35 |
|
|
CcKeyboardManager *manager; |
36 |
|
|
CcKeyboardShortcutEditor *shortcut_editor; |
37 |
|
|
}; |
38 |
|
|
|
39 |
|
✗ |
G_DEFINE_TYPE (CcKeyboardShortcutRow, cc_keyboard_shortcut_row, ADW_TYPE_ACTION_ROW) |
40 |
|
|
|
41 |
|
|
static void |
42 |
|
✗ |
reset_shortcut_cb (CcKeyboardShortcutRow *self) |
43 |
|
|
{ |
44 |
|
✗ |
cc_keyboard_manager_reset_shortcut (self->manager, self->item); |
45 |
|
✗ |
} |
46 |
|
|
|
47 |
|
|
static void |
48 |
|
✗ |
cc_keyboard_shortcut_row_class_init (CcKeyboardShortcutRowClass *klass) |
49 |
|
|
{ |
50 |
|
✗ |
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); |
51 |
|
|
|
52 |
|
✗ |
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/control-center/keyboard/cc-keyboard-shortcut-row.ui"); |
53 |
|
|
|
54 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CcKeyboardShortcutRow, accelerator_label); |
55 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CcKeyboardShortcutRow, reset_button); |
56 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CcKeyboardShortcutRow, reset_revealer); |
57 |
|
|
|
58 |
|
✗ |
gtk_widget_class_bind_template_callback (widget_class, reset_shortcut_cb); |
59 |
|
✗ |
} |
60 |
|
|
|
61 |
|
|
static void |
62 |
|
✗ |
cc_keyboard_shortcut_row_init (CcKeyboardShortcutRow *self) |
63 |
|
|
{ |
64 |
|
✗ |
gtk_widget_init_template (GTK_WIDGET (self)); |
65 |
|
✗ |
} |
66 |
|
|
|
67 |
|
|
static void |
68 |
|
✗ |
cc_kbd_shortcut_is_default_changed_cb (CcKeyboardShortcutRow *self) |
69 |
|
|
{ |
70 |
|
|
/* Embolden the label when the shortcut is modified */ |
71 |
|
✗ |
if (cc_keyboard_item_is_value_default (self->item)) |
72 |
|
✗ |
gtk_widget_remove_css_class (GTK_WIDGET (self->accelerator_label), "heading"); |
73 |
|
|
else |
74 |
|
✗ |
gtk_widget_add_css_class (GTK_WIDGET (self->accelerator_label), "heading"); |
75 |
|
✗ |
} |
76 |
|
|
|
77 |
|
|
static gboolean |
78 |
|
✗ |
transform_binding_to_accel (GBinding *binding, |
79 |
|
|
const GValue *from_value, |
80 |
|
|
GValue *to_value, |
81 |
|
|
gpointer user_data) |
82 |
|
|
{ |
83 |
|
✗ |
g_autoptr(CcKeyboardItem) item = NULL; |
84 |
|
|
CcKeyCombo combo; |
85 |
|
|
gchar *accelerator; |
86 |
|
|
|
87 |
|
✗ |
item = CC_KEYBOARD_ITEM (g_binding_dup_source (binding)); |
88 |
|
✗ |
combo = cc_keyboard_item_get_primary_combo (item); |
89 |
|
✗ |
accelerator = convert_keysym_state_to_string (&combo); |
90 |
|
|
|
91 |
|
✗ |
g_value_take_string (to_value, accelerator); |
92 |
|
|
|
93 |
|
✗ |
return TRUE; |
94 |
|
|
} |
95 |
|
|
|
96 |
|
|
CcKeyboardShortcutRow * |
97 |
|
✗ |
cc_keyboard_shortcut_row_new (CcKeyboardItem *item, |
98 |
|
|
CcKeyboardManager *manager, |
99 |
|
|
CcKeyboardShortcutEditor *shortcut_editor, |
100 |
|
|
GtkSizeGroup *size_group) |
101 |
|
|
{ |
102 |
|
|
CcKeyboardShortcutRow *self; |
103 |
|
|
|
104 |
|
✗ |
self = g_object_new (CC_TYPE_KEYBOARD_SHORTCUT_ROW, NULL); |
105 |
|
✗ |
self->item = item; |
106 |
|
✗ |
self->manager = manager; |
107 |
|
✗ |
self->shortcut_editor = shortcut_editor; |
108 |
|
|
|
109 |
|
✗ |
g_object_bind_property (item, "description", |
110 |
|
|
self, "title", |
111 |
|
|
G_BINDING_SYNC_CREATE); |
112 |
|
✗ |
g_object_bind_property (item, "is-value-default", |
113 |
|
✗ |
self->reset_revealer, "reveal-child", |
114 |
|
|
G_BINDING_SYNC_CREATE | G_BINDING_INVERT_BOOLEAN); |
115 |
|
✗ |
g_object_bind_property_full (item, |
116 |
|
|
"key-combos", |
117 |
|
✗ |
self->accelerator_label, |
118 |
|
|
"label", |
119 |
|
|
G_BINDING_SYNC_CREATE, |
120 |
|
|
transform_binding_to_accel, |
121 |
|
|
NULL, NULL, NULL); |
122 |
|
|
|
123 |
|
✗ |
g_signal_connect_object (item, "notify::is-value-default", |
124 |
|
|
G_CALLBACK (cc_kbd_shortcut_is_default_changed_cb), |
125 |
|
|
self, G_CONNECT_SWAPPED); |
126 |
|
✗ |
cc_kbd_shortcut_is_default_changed_cb (self); |
127 |
|
|
|
128 |
|
✗ |
gtk_size_group_add_widget(size_group, |
129 |
|
✗ |
GTK_WIDGET (self->accelerator_label)); |
130 |
|
|
|
131 |
|
✗ |
return self; |
132 |
|
|
} |
133 |
|
|
|
134 |
|
|
CcKeyboardItem * |
135 |
|
✗ |
cc_keyboard_shortcut_row_get_item (CcKeyboardShortcutRow *self) |
136 |
|
|
{ |
137 |
|
✗ |
g_return_val_if_fail (CC_IS_KEYBOARD_SHORTCUT_ROW (self), NULL); |
138 |
|
|
|
139 |
|
✗ |
return self->item; |
140 |
|
|
} |
141 |
|
|
|