1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
| | /* Event handling for GTK 3 and (in the future) GTK 4 -*- coding: utf-8 -*-
Copyright (C) 2020 Free Software Foundation, Inc.
This file is part of GNU Emacs.
GNU Emacs is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or (at
your option) any later version.
GNU Emacs is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
#ifndef __PGTK_EVENT_H
#define __PGTK_EVENT_H
#include "config.h"
#include "gtkconfig.h"
#include <gtk/gtk.h>
G_BEGIN_DECLS
#if !defined (HAVE_GTK4) || defined (FIX_GTK_LEGACY_CONTROLLER_BUG)
/* ATTENTION *
* If Emacs fails to compile, or throws weird
* errors during runtime, make sure to update
* this section with the contents of gtkeventcontrollerprivate.h
* from the GTK version you're using
*/
#ifndef HAVE_GTK4
struct _GtkEventController
{
GObject parent_instance;
};
struct _GtkEventControllerClass
{
GObjectClass parent_class;
void (* set_widget) (GtkEventController *controller,
GtkWidget *widget);
void (* unset_widget) (GtkEventController *controller);
gboolean (* handle_event) (GtkEventController *controller,
const GdkEvent *event);
void (* reset) (GtkEventController *controller);
/*<private>*/
/* Tells whether the event is filtered out, %TRUE makes
* the event unseen by the handle_event vfunc.
*/
gboolean (* filter_event) (GtkEventController *controller,
const GdkEvent *event);
gpointer padding[10];
};
#else
typedef enum {
GTK_CROSSING_FOCUS,
GTK_CROSSING_POINTER,
GTK_CROSSING_DROP
} GtkCrossingType;
typedef enum {
GTK_CROSSING_IN,
GTK_CROSSING_OUT
} GtkCrossingDirection;
typedef struct _GtkCrossingData GtkCrossingData;
/**
* GtkCrossingData:
* @type: the type of crossing event
* @direction: whether this is a focus-in or focus-out event
* @mode: the crossing mode
* @old_target: the old target
* @old_descendent: the direct child of the receiving widget that
* is an ancestor of @old_target, or %NULL if @old_target is not
* a descendent of the receiving widget
* @new_target: the new target
* @new_descendent: the direct child of the receiving widget that
* is an ancestor of @new_target, or %NULL if @new_target is not
* a descendent of the receiving widget
* @drop: the #GdkDrop if this is info for a drop operation
*
* The struct that is passed to gtk_event_controller_handle_crossing().
*
* The @old_target and @new_target fields are set to the old or new
* focus, drop or hover location.
*/
struct _GtkCrossingData {
GtkCrossingType type;
GtkCrossingDirection direction;
GdkCrossingMode mode;
GtkWidget *old_target;
GtkWidget *old_descendent;
GtkWidget *new_target;
GtkWidget *new_descendent;
GdkDrop *drop;
};
struct _GtkEventController
{
GObject parent_instance;
};
struct _GtkEventControllerClass
{
GObjectClass parent_class;
void (* set_widget) (GtkEventController *controller,
GtkWidget *widget);
void (* unset_widget) (GtkEventController *controller);
gboolean (* handle_event) (GtkEventController *controller,
GdkEvent *event,
double x,
double y);
void (* reset) (GtkEventController *controller);
void (* handle_crossing) (GtkEventController *controller,
const GtkCrossingData *crossing,
double x,
double y);
/*<private>*/
/* Tells whether the event is filtered out, %TRUE makes
* the event unseen by the handle_event vfunc.
*/
gboolean (* filter_event) (GtkEventController *controller,
GdkEvent *event);
gpointer padding[10];
};
#endif
#endif
struct _EmacsGtkEventHandler
{
#if !defined (HAVE_GTK4) || defined (FIX_GTK_LEGACY_HANDLER_BUG)
GtkEventController parent_instance;
#else
GObject parent_instance;
#endif
#ifdef HAVE_GTK4
// FIXME stupid hack
gchar padding[1280];
#endif
GtkWidget *widget;
gboolean (*key_down) (GtkWidget *w, GdkEvent *ev, struct frame *frame);
gboolean (*key_up) (GtkWidget *w, GdkEvent *ev, struct frame *f);
gboolean (*button_down) (GtkWidget *w, GdkEvent *ev, struct frame *f);
gboolean (*button_up) (GtkWidget *w, GdkEvent *ev, struct frame *f);
gboolean (*window_state_event) (GtkWidget *w, GdkEvent *ev, struct frame *f);
gboolean (*delete_event) (GtkWidget *w, GdkEvent *ev, struct frame *f);
gboolean (*map_event) (GtkWidget *w, GdkEvent *ev, struct frame *f);
gboolean (*size_allocate) (GtkWidget *w, GdkEvent *ev, struct frame *f);
#ifndef HAVE_GTK4
gboolean (*scroll_event) (GtkWidget *w, GdkEvent *ev, struct frame *f);
#else
gboolean (*scroll_event) (GtkEventControllerScroll *widget,
gdouble dx,
gdouble dy,
struct frame *_);
gboolean (*long_press_event) (struct frame *f, gdouble ex, gdouble ey);
#endif
#ifndef HAVE_GTK4
gboolean (*selection_lost) (GtkWidget *w, GdkEventSelection *ev, struct frame *f);
#endif
gboolean (*configure) (GtkWidget *w, GdkEvent *ev, struct frame *f);
#ifndef HAVE_GTK4
gboolean (*expose) (GtkWidget *w, GdkEventExpose *ev, gpointer ignored);
#endif
gboolean (*focus_in) (GtkWidget *w, GdkEvent *ev, gpointer frame_ptr);
gboolean (*focus_out) (GtkWidget *w, GdkEvent *ev, gpointer frame_ptr);
#ifdef HAVE_GTK4
gboolean (*enter_notify) (GtkWidget *w, GdkEvent *ev, gpointer frame_ptr);
gboolean (*leave_notify) (GtkWidget *w, GdkEvent *ev, gpointer frame_ptr);
gboolean (*motion_notify) (GtkWidget *w, GdkEvent *ev, gpointer frame_ptr);
void (*enter) (GtkWidget *w, GdkCrossingMode cm, struct frame *f);
void (*leave) (GtkWidget *w, GdkCrossingMode cm, struct frame *f);
#ifndef FIX_GTK_LEGACY_HANDLER_BUG
GtkEventControllerLegacy *legacy;
#endif
#ifdef HAVE_GTK4
GtkEventControllerScroll *scroll;
GtkEventControllerMotion *focus;
GtkGesture *drag;
GtkGesture *lpress;
gdouble dsy, dsx;
bool_bf s_flag;
bool_bf hq_flag;
bool_bf se_blocked;
#endif
#endif
};
#define EMACS_TYPE_GTK_EVENT_HANDLER (emacs_gtk_event_handler_get_type ())
G_DECLARE_FINAL_TYPE (EmacsGtkEventHandler,
emacs_gtk_event_handler,
EMACS,
#if !defined (HAVE_GTK4) || defined (FIX_GTK_LEGACY_HANDLER_BUG)
GTK_EVENT_HANDLER
#else
G_OBJECT
#endif
,
#if !defined (HAVE_GTK4) || defined (FIX_GTK_LEGACY_HANDLER_BUG)
GtkEventController
#else
GObject
#endif
)
EmacsGtkEventHandler *emacs_gtk_event_handler_new (struct frame *f);
void
emacs_gtk_event_handler_set_widget (EmacsGtkEventHandler *handler, GtkWidget *w);
#ifdef HAVE_GTK4
void
emacs_gtk_event_handler_toggle_scroll_evs (EmacsGtkEventHandler *handler,
bool enable);
#endif
G_END_DECLS
#endif /* __PGTK_EVENT_H */
|