1 /* dzl-shortcut-private.h
2  *
3  * Copyright (C) 2017 Christian Hergert <chergert@redhat.com>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #pragma once
20 
21 #include "shortcuts/dzl-shortcut-chord.h"
22 #include "shortcuts/dzl-shortcut-closure-chain.h"
23 #include "shortcuts/dzl-shortcut-controller.h"
24 #include "shortcuts/dzl-shortcut-simple-label.h"
25 #include "shortcuts/dzl-shortcut-manager.h"
26 #include "shortcuts/dzl-shortcut-theme.h"
27 
28 G_BEGIN_DECLS
29 
30 #define DZL_SHORTCUT_CLOSURE_CHAIN_MAGIC 0x81236261
31 #define DZL_SHORTCUT_NODE_DATA_MAGIC     0x81746332
32 
33 typedef struct
34 {
35   DzlShortcutChordTable *table;
36   guint                  position;
37 } DzlShortcutChordTableIter;
38 
39 typedef enum
40 {
41   DZL_SHORTCUT_NODE_SECTION = 1,
42   DZL_SHORTCUT_NODE_GROUP,
43   DZL_SHORTCUT_NODE_ACTION,
44   DZL_SHORTCUT_NODE_COMMAND,
45 } DzlShortcutNodeType;
46 
47 typedef struct
48 {
49   DzlShortcutNodeType  type;
50   guint                magic;
51   const gchar         *name;
52   const gchar         *title;
53   const gchar         *subtitle;
54 } DzlShortcutNodeData;
55 
56 typedef enum
57 {
58   DZL_SHORTCUT_MODEL_COLUMN_TYPE,
59   DZL_SHORTCUT_MODEL_COLUMN_ID,
60   DZL_SHORTCUT_MODEL_COLUMN_TITLE,
61   DZL_SHORTCUT_MODEL_COLUMN_ACCEL,
62   DZL_SHORTCUT_MODEL_COLUMN_KEYWORDS,
63   DZL_SHORTCUT_MODEL_COLUMN_CHORD,
64   DZL_SHORTCUT_MODEL_N_COLUMNS
65 } DzlShortcutModelColumn;
66 
67 typedef enum
68 {
69   DZL_SHORTCUT_CLOSURE_ACTION = 1,
70   DZL_SHORTCUT_CLOSURE_CALLBACK,
71   DZL_SHORTCUT_CLOSURE_COMMAND,
72   DZL_SHORTCUT_CLOSURE_SIGNAL,
73   DZL_SHORTCUT_CLOSURE_LAST
74 } DzlShortcutClosureType;
75 
76 struct _DzlShortcutClosureChain
77 {
78   GSList node;
79 
80   guint magic;
81 
82   DzlShortcutClosureType type : 3;
83   DzlShortcutPhase phase : 3;
84   guint executing : 1;
85 
86   union {
87     struct {
88       const gchar *group;
89       const gchar *name;
90       GVariant    *params;
91     } action;
92     struct {
93       const gchar *name;
94     } command;
95     struct {
96       GQuark       detail;
97       const gchar *name;
98       GArray      *params;
99     } signal;
100     struct {
101       GtkCallback    callback;
102       gpointer       user_data;
103       GDestroyNotify notify;
104     } callback;
105   };
106 };
107 
108 DzlShortcutMatch       _dzl_shortcut_controller_handle              (DzlShortcutController      *self,
109                                                                      const GdkEventKey          *event,
110                                                                      const DzlShortcutChord     *chord,
111                                                                      DzlShortcutPhase            phase,
112                                                                      GtkWidget                  *widget);
113 DzlShortcutChord      *_dzl_shortcut_controller_push                (DzlShortcutController      *self,
114                                                                      const GdkEventKey          *event);
115 void                   _dzl_shortcut_controller_clear               (DzlShortcutController      *self);
116 GNode                 *_dzl_shortcut_manager_get_root               (DzlShortcutManager         *self);
117 DzlShortcutTheme      *_dzl_shortcut_manager_get_internal_theme     (DzlShortcutManager         *self);
118 void                   _dzl_shortcut_simple_label_set_size_group    (DzlShortcutSimpleLabel     *self,
119                                                                      GtkSizeGroup               *size_group);
120 void                   _dzl_shortcut_theme_attach                   (DzlShortcutTheme           *self);
121 void                   _dzl_shortcut_theme_detach                   (DzlShortcutTheme           *self);
122 GtkTreeModel          *_dzl_shortcut_theme_create_model             (DzlShortcutTheme           *self);
123 GHashTable            *_dzl_shortcut_theme_get_contexts             (DzlShortcutTheme           *self);
124 DzlShortcutContext    *_dzl_shortcut_theme_try_find_context_by_name (DzlShortcutTheme           *self,
125                                                                      const gchar                *name);
126 DzlShortcutContext     *_dzl_shortcut_theme_find_default_context_with_phase
127                                                                     (DzlShortcutTheme           *self,
128                                                                      GtkWidget                  *widget,
129                                                                      DzlShortcutPhase            phase);
130 void                   _dzl_shortcut_theme_set_manager              (DzlShortcutTheme           *self,
131                                                                      DzlShortcutManager         *manager);
132 void                   _dzl_shortcut_theme_set_name                 (DzlShortcutTheme           *self,
133                                                                      const gchar                *name);
134 const gchar           *_dzl_shortcut_theme_lookup_action            (DzlShortcutTheme           *self,
135                                                                      const DzlShortcutChord     *chord);
136 void                   _dzl_shortcut_theme_merge                    (DzlShortcutTheme           *self,
137                                                                      DzlShortcutTheme           *layer);
138 DzlShortcutMatch       _dzl_shortcut_theme_match                    (DzlShortcutTheme           *self,
139                                                                      DzlShortcutPhase            phase,
140                                                                      const DzlShortcutChord     *chord,
141                                                                      DzlShortcutClosureChain   **chain);
142 gboolean               _dzl_shortcut_context_contains               (DzlShortcutContext         *self,
143                                                                      const DzlShortcutChord     *chord);
144 DzlShortcutChordTable *_dzl_shortcut_context_get_table              (DzlShortcutContext         *self);
145 void                   _dzl_shortcut_context_merge                  (DzlShortcutContext         *self,
146                                                                      DzlShortcutContext         *layer);
147 void                   _dzl_shortcut_chord_table_iter_init          (DzlShortcutChordTableIter  *iter,
148                                                                      DzlShortcutChordTable      *table);
149 gboolean               _dzl_shortcut_chord_table_iter_next          (DzlShortcutChordTableIter  *iter,
150                                                                      const DzlShortcutChord    **chord,
151                                                                      gpointer                   *value);
152 void                   _dzl_shortcut_chord_table_iter_steal         (DzlShortcutChordTableIter  *iter);
153 gboolean               _dzl_shortcut_manager_get_command_info       (DzlShortcutManager         *self,
154                                                                      const gchar                *command_id,
155                                                                      const gchar               **title,
156                                                                      const gchar               **subtitle);
157 
158 static inline gboolean
DZL_IS_SHORTCUT_CLOSURE_CHAIN(DzlShortcutClosureChain * self)159 DZL_IS_SHORTCUT_CLOSURE_CHAIN (DzlShortcutClosureChain *self)
160 {
161   return self != NULL && self->magic == DZL_SHORTCUT_CLOSURE_CHAIN_MAGIC;
162 }
163 
164 static inline gboolean
DZL_IS_SHORTCUT_NODE_DATA(DzlShortcutNodeData * data)165 DZL_IS_SHORTCUT_NODE_DATA (DzlShortcutNodeData *data)
166 {
167   return data != NULL && data->magic == DZL_SHORTCUT_NODE_DATA_MAGIC;
168 }
169 
170 G_END_DECLS
171