Révision | f9fc4878bc05dd4e9375e09829b4e7fa2c8a02f5 (tree) |
---|---|
l'heure | 2023-03-19 14:33:27 |
Auteur | phabrics <phabrics@phab...> |
Commiter | phabrics |
Finalized structure of display for GTK4 migration.
@@ -227,10 +227,9 @@ _tme_keyboard_keyval_name(tme_keyboard_keyval_t keyval) | ||
227 | 227 | |
228 | 228 | /* this is a generic callback for a key press or release event: */ |
229 | 229 | int |
230 | -_tme_keyboard_key_event(int down, tme_keyboard_keyval_t key, void *disp) | |
230 | +_tme_keyboard_key_event(int down, tme_keyboard_keyval_t key, struct tme_display *display) | |
231 | 231 | { |
232 | 232 | struct tme_keyboard_event tme_event; |
233 | - struct tme_display *display = (_tme_display_get) ? (_tme_display_get(disp)) : (disp); | |
234 | 233 | int was_empty; |
235 | 234 | int new_callouts; |
236 | 235 | int rc; |
@@ -53,31 +53,23 @@ _tme_mouse_debug(const struct tme_mouse_event *event) | ||
53 | 53 | #endif |
54 | 54 | |
55 | 55 | /* this is a generic callback for a mouse event: */ |
56 | -int | |
57 | -_tme_mouse_button_press(int button, int x, int y, struct tme_display *display) | |
56 | +void | |
57 | +_tme_mouse_event(int button, int x, int y, struct tme_display *display) | |
58 | 58 | { |
59 | - int state; | |
60 | - | |
59 | + struct tme_mouse_event tme_event; | |
60 | + int was_empty; | |
61 | + int new_callouts, rc; | |
62 | + | |
61 | 63 | /* make the buttons mask: */ |
62 | - state = display->tme_screen_mouse_buttons_last; | |
64 | + int buttons = display->tme_screen_mouse_buttons_last; | |
63 | 65 | |
64 | 66 | if(button>0) |
65 | - state |= TME_BIT(button-1); | |
67 | + buttons |= TME_BIT(button-1); | |
66 | 68 | else if(button) { |
67 | 69 | button = -button; |
68 | - state &= ~TME_BIT(button-1); | |
70 | + buttons &= ~TME_BIT(button-1); | |
69 | 71 | } |
70 | 72 | |
71 | - return _tme_mouse_buttons_event(state, x, y, display); | |
72 | -} | |
73 | - | |
74 | -int _tme_mouse_buttons_event(int buttons, int x, int y, void *disp) | |
75 | -{ | |
76 | - struct tme_mouse_event tme_event; | |
77 | - int was_empty; | |
78 | - int new_callouts, rc; | |
79 | - struct tme_display *display = (_tme_display_get) ? (_tme_display_get(disp)) : (disp); | |
80 | - | |
81 | 73 | /* start the tme event: */ |
82 | 74 | tme_event.tme_mouse_event_delta_units |
83 | 75 | = TME_MOUSE_UNITS_UNKNOWN; |
@@ -100,7 +92,7 @@ int _tme_mouse_buttons_event(int buttons, int x, int y, void *disp) | ||
100 | 92 | tme_mutex_unlock(&display->tme_display_mutex); |
101 | 93 | |
102 | 94 | /* stop propagating this event: */ |
103 | - return (TRUE); | |
95 | + return; | |
104 | 96 | } |
105 | 97 | |
106 | 98 | tme_event.tme_mouse_event_buttons = |
@@ -145,9 +137,6 @@ int _tme_mouse_buttons_event(int buttons, int x, int y, void *disp) | ||
145 | 137 | |
146 | 138 | /* unlock the mutex: */ |
147 | 139 | tme_mutex_unlock(&display->tme_display_mutex); |
148 | - | |
149 | - /* don't process this event any further: */ | |
150 | - return (TRUE); | |
151 | 140 | } |
152 | 141 | |
153 | 142 | /* this is called when the mouse controls change: */ |
@@ -36,8 +36,6 @@ | ||
36 | 36 | /* includes: */ |
37 | 37 | #include "display.h" |
38 | 38 | |
39 | -struct tme_display *(*_tme_display_get) _TME_P((void *)); | |
40 | - | |
41 | 39 | static int |
42 | 40 | _tme_screen_update(struct tme_screen *screen) { |
43 | 41 | struct tme_fb_connection *conn_fb; |
@@ -689,9 +687,6 @@ int tme_display_init(struct tme_element *element, | ||
689 | 687 | /* start our data structure: */ |
690 | 688 | display->tme_display_element = element; |
691 | 689 | |
692 | - /* default display: */ | |
693 | - _tme_display_get = 0; | |
694 | - | |
695 | 690 | /* create the keyboard: */ |
696 | 691 | _tme_keyboard_new(display); |
697 | 692 |
@@ -186,7 +186,6 @@ _tme_scanline_pad(int bpl) | ||
186 | 186 | return (8); |
187 | 187 | } |
188 | 188 | |
189 | -extern struct tme_display *(*_tme_display_get) _TME_P((void *)); | |
190 | 189 | struct tme_screen *_tme_screen_add _TME_P((struct tme_display *, |
191 | 190 | size_t, |
192 | 191 | struct tme_connection *)); |
@@ -197,12 +196,12 @@ void _tme_screen_xlat_set _TME_P((struct tme_screen *screen)); | ||
197 | 196 | void _tme_keyboard_new _TME_P((struct tme_display *)); |
198 | 197 | int _tme_keyboard_connections_new _TME_P((struct tme_display *, |
199 | 198 | struct tme_connection **)); |
200 | -int _tme_keyboard_key_event _TME_P((int down, tme_keyboard_keyval_t key, void *disp)); | |
199 | +int _tme_keyboard_key_event _TME_P((int down, tme_keyboard_keyval_t key, struct tme_display *disp)); | |
201 | 200 | void _tme_mouse_new _TME_P((struct tme_display *)); |
202 | 201 | void _tme_mouse_mode_off _TME_P((struct tme_screen *, tme_uint32_t)); |
203 | 202 | int _tme_mouse_connections_new _TME_P((struct tme_display *, |
204 | 203 | struct tme_connection **)); |
205 | -int _tme_mouse_buttons_event _TME_P((int buttons, int x, int y, void *disp)); | |
204 | +void _tme_mouse_event _TME_P((int button, int x, int y, struct tme_display *disp)); | |
206 | 205 | |
207 | 206 | #endif /* _HOST_DISPLAY_H */ |
208 | 207 |
@@ -98,8 +98,8 @@ typedef struct tme_gtk_screen { | ||
98 | 98 | guint tme_gtk_screen_mouse_statusbar_cid; |
99 | 99 | |
100 | 100 | cairo_format_t tme_gtk_screen_format; |
101 | - GtkEventControllerKey *key; | |
102 | - GtkEventControllerMotion *motion; | |
101 | + GtkEventController *key, *mouse, *motion, *event; | |
102 | + GtkGesture *press; | |
103 | 103 | |
104 | 104 | /* when mouse mode is on, this is the previous events mask |
105 | 105 | for the framebuffer event box: */ |
@@ -50,9 +50,25 @@ _tme_gtk_keyboard_key_down( | ||
50 | 50 | guint keyval, |
51 | 51 | guint keycode, |
52 | 52 | GdkModifierType* state, |
53 | - struct tme_display *display) | |
53 | + struct tme_gtk_screen *screen) | |
54 | 54 | { |
55 | - return _tme_keyboard_key_event(TRUE, keyval, display); | |
55 | + if(screen->tme_gtk_screen_mouse_keyval | |
56 | + != keyval) | |
57 | + return _tme_keyboard_key_event(TRUE, keyval, screen->screen.tme_screen_display); | |
58 | + | |
59 | + /* pop our message off of the statusbar: */ | |
60 | + gtk_statusbar_pop(GTK_STATUSBAR(screen->tme_gtk_screen_mouse_statusbar), | |
61 | + screen->tme_gtk_screen_mouse_statusbar_cid); | |
62 | + | |
63 | + /* restore the text on the mouse label: */ | |
64 | + gtk_frame_set_label(GTK_FRAME(screen->tme_gtk_screen_mouse_label), | |
65 | + _("Mouse is off")); | |
66 | + | |
67 | + /* the mouse is now off: */ | |
68 | + screen->tme_gtk_screen_mouse_keyval = GDK_KEY_VoidSymbol; | |
69 | + | |
70 | + return (TRUE); | |
71 | + | |
56 | 72 | } |
57 | 73 | |
58 | 74 | static gboolean |
@@ -61,46 +77,100 @@ _tme_gtk_keyboard_key_up( | ||
61 | 77 | guint keyval, |
62 | 78 | guint keycode, |
63 | 79 | GdkModifierType* state, |
64 | - struct tme_display *display) | |
80 | + struct tme_gtk_screen *screen) | |
81 | +{ | |
82 | + return _tme_keyboard_key_event(FALSE, keyval, screen->screen.tme_screen_display); | |
83 | +} | |
84 | + | |
85 | +/* this sets the mouse mode, e.g., on/off. it is called with the mutex locked: */ | |
86 | +static gboolean | |
87 | +_tme_gtk_mouse_key_down( | |
88 | + GtkEventControllerKey* self, | |
89 | + guint keyval, | |
90 | + guint keycode, | |
91 | + GdkModifierType* state, | |
92 | + struct tme_gtk_screen *screen) | |
65 | 93 | { |
66 | - return _tme_keyboard_key_event(FALSE, keyval, display); | |
94 | + struct tme_gtk_display *display; | |
95 | + int rc; | |
96 | + char *status; | |
97 | + | |
98 | + /* recover our data structure: */ | |
99 | + display = screen->screen.tme_screen_display; | |
100 | + | |
101 | + if(screen->tme_gtk_screen_mouse_keyval | |
102 | + != GDK_KEY_VoidSymbol) return (FALSE); | |
103 | + | |
104 | + /* lock the mutex: */ | |
105 | + tme_mutex_lock(&display->display.tme_display_mutex); | |
106 | + | |
107 | + /* this keyval must not be GDK_KEY_VoidSymbol: */ | |
108 | + assert (keyval | |
109 | + != GDK_KEY_VoidSymbol); | |
110 | + | |
111 | + /* set the text on the mouse label: */ | |
112 | + gtk_frame_set_label(GTK_FRAME(screen->tme_gtk_screen_mouse_label), | |
113 | + _("Mouse is on")); | |
114 | + | |
115 | + /* push the mouse status onto the statusbar: */ | |
116 | + status = NULL; | |
117 | + tme_output_append(&status, | |
118 | + _("Press the %s key to turn the mouse off"), | |
119 | + gdk_keyval_name(keyval)); | |
120 | + gtk_statusbar_push(GTK_STATUSBAR(screen->tme_gtk_screen_mouse_statusbar), | |
121 | + screen->tme_gtk_screen_mouse_statusbar_cid, | |
122 | + status); | |
123 | + tme_free(status); | |
124 | + | |
125 | + gdk_device_get_position(gdk_seat_get_pointer(display->tme_gdk_display_seat), | |
126 | + NULL, | |
127 | + &display->display.tme_screen_mouse_warp_x, | |
128 | + &display->display.tme_screen_mouse_warp_y); | |
129 | + | |
130 | + /* we are now in mouse mode: */ | |
131 | + screen->tme_gtk_screen_mouse_keyval | |
132 | + = keyval; | |
133 | + | |
134 | + /* unlock the mutex: */ | |
135 | + tme_mutex_unlock(&display->display.tme_display_mutex); | |
136 | + | |
137 | + return (TRUE); | |
67 | 138 | } |
68 | 139 | |
69 | 140 | /* this attaches the GTK keyboard to a new screen: */ |
70 | 141 | void |
71 | 142 | _tme_gtk_keyboard_attach(struct tme_gtk_screen *screen) |
72 | 143 | { |
73 | - GtkEventControllerKey *key; | |
74 | - GtkEventControllerMotion *motion; | |
144 | + GtkEventController *key, *mouse; | |
75 | 145 | |
76 | 146 | #if GTK_MAJOR_VERSION == 4 |
77 | - motion=gtk_event_controller_motion_new(); | |
78 | 147 | key=gtk_event_controller_key_new(); |
79 | - gtk_widget_add_controller(screen->tme_gtk_screen_draw, GTK_EVENT_CONTROLLER(key)); | |
80 | - gtk_widget_add_controller(screen->tme_gtk_screen_draw, GTK_EVENT_CONTROLLER(motion)); | |
148 | + gtk_widget_add_controller(screen->tme_gtk_screen_draw, key); | |
149 | + gtk_widget_set_focussable(screen->tme_gtk_screen_draw, TRUE); | |
150 | + mouse=gtk_event_controller_key_new(); | |
151 | + gtk_widget_add_controller(screen->tme_gtk_screen_mouse_label, mouse); | |
152 | + gtk_widget_set_focussable(screen->tme_gtk_screen_mouse_label, TRUE); | |
81 | 153 | #elif GTK_MAJOR_VERSION == 3 |
82 | - motion=screen->motion=gtk_event_controller_motion_new(screen->tme_gtk_screen_draw); | |
83 | 154 | key=screen->key=gtk_event_controller_key_new(screen->tme_gtk_screen_draw); |
155 | + gtk_widget_set_can_focus(screen->tme_gtk_screen_draw, TRUE); | |
156 | + mouse=screen->mouse=gtk_event_controller_key_new(screen->tme_gtk_screen_mouse_label); | |
157 | + gtk_widget_set_can_focus(screen->tme_gtk_screen_mouse_label, TRUE); | |
84 | 158 | #endif |
85 | 159 | |
86 | - /* on entering window, grab keyboard focus: */ | |
87 | - g_signal_connect_swapped(motion, | |
88 | - "enter", | |
89 | - G_CALLBACK(gtk_widget_grab_focus), | |
90 | - screen->tme_gtk_screen_draw); | |
91 | - | |
92 | 160 | g_signal_connect_after(key, |
93 | 161 | "key-pressed", |
94 | 162 | G_CALLBACK(_tme_gtk_keyboard_key_down), |
95 | - screen->screen.tme_screen_display); | |
163 | + screen); | |
164 | + | |
96 | 165 | g_signal_connect_after(key, |
97 | 166 | "key-released", |
98 | 167 | G_CALLBACK(_tme_gtk_keyboard_key_up), |
99 | - screen->screen.tme_screen_display); | |
100 | - | |
101 | - /* the event box can focus, and have it grab the focus now: */ | |
102 | - gtk_widget_set_can_focus(screen->tme_gtk_screen_draw, TRUE); | |
103 | - gtk_widget_grab_focus(screen->tme_gtk_screen_draw); | |
168 | + screen); | |
169 | + | |
170 | + g_signal_connect_after(mouse, | |
171 | + "key-pressed", | |
172 | + G_CALLBACK(_tme_gtk_mouse_key_down), | |
173 | + screen); | |
104 | 174 | |
105 | 175 | } |
106 | 176 |
@@ -56,231 +56,88 @@ _tme_gtk_mouse_warp_pointer(struct tme_gtk_screen *screen) | ||
56 | 56 | screen->screen.tme_screen_mouse_warp_y); |
57 | 57 | } |
58 | 58 | #endif |
59 | -/* this is a GTK callback for a mouse event in the framebuffer event box: */ | |
60 | -static int | |
61 | -_tme_gtk_mouse_mouse_event(GtkWidget *widget, | |
62 | - GdkEvent *gdk_event_raw, | |
63 | - struct tme_gtk_screen *display) | |
64 | -{ | |
65 | - gint x; | |
66 | - gint y; | |
67 | - int button=0; | |
68 | - | |
69 | -#if GTK_MAJOR_VERSION == 4 | |
70 | - gdk_event_get_position(gdk_event_raw, &x, &y); | |
71 | - button = gdk_button_event_get_button(gdk_event_raw); | |
72 | - | |
73 | -#elif GTK_MAJOR_VERSION == 3 | |
74 | - /* if this is motion: */ | |
75 | - if (gdk_event_raw->type == GDK_MOTION_NOTIFY) { | |
76 | - | |
77 | - /* if the pointer position hasn't changed either, return now. | |
78 | - every time we warp the pointer we will get a motion event, and | |
79 | - this should ignore those events: */ | |
80 | - x = gdk_event_raw->motion.x; | |
81 | - y = gdk_event_raw->motion.y; | |
82 | - | |
83 | - } | |
84 | - | |
85 | - /* otherwise, this must be a button press or a release: */ | |
86 | - else { | |
87 | 59 | |
88 | - /* get the pointer position: */ | |
89 | - x = gdk_event_raw->button.x; | |
90 | - y = gdk_event_raw->button.y; | |
91 | - | |
92 | - /* make the buttons mask: */ | |
93 | - button = gdk_event_raw->button.button; | |
94 | - if(gdk_event_raw->type == GDK_BUTTON_RELEASE) | |
95 | - button = -button; | |
96 | - } | |
97 | - | |
98 | - /* otherwise, if this is a double- or triple-click: */ | |
99 | - if (gdk_event_raw->type != GDK_2BUTTON_PRESS | |
100 | - && gdk_event_raw->type != GDK_3BUTTON_PRESS) | |
101 | -#endif | |
102 | - { | |
103 | - /* we ignore double- and triple-click events, since normal button | |
104 | - press and release events are always generated also: */ | |
105 | - // assert (gdk_event_raw->type == GDK_BUTTON_PRESS || gdk_event_raw->type == GDK_BUTTON_RELEASE); | |
106 | - | |
107 | - _tme_mouse_button_press(button, x, y, display); | |
108 | - | |
109 | - } | |
60 | +/* this is a GTK callback for a mouse event in the framebuffer event box: */ | |
61 | +static void | |
62 | +_tme_gtk_mouse_motion_event(GtkEventControllerMotion* self, | |
63 | + gdouble x, | |
64 | + gdouble y, | |
65 | + struct tme_gtk_screen *screen) | |
110 | 66 | |
111 | - /* stop propagating this event: */ | |
112 | - return (TRUE); | |
67 | +{ | |
68 | + if(screen->tme_gtk_screen_mouse_keyval | |
69 | + != GDK_KEY_VoidSymbol) | |
70 | + _tme_mouse_event(0, x, y, screen->screen.tme_screen_display); | |
113 | 71 | } |
114 | 72 | |
115 | -/* this is a GTK callback for an event in the event box containing the | |
116 | - mouse label: */ | |
117 | -static int | |
118 | -_tme_gtk_mouse_ebox_event(GtkWidget *widget, | |
119 | - GdkEvent *gdk_event_raw, | |
120 | - struct tme_gtk_screen *screen) | |
73 | +/* this is a GTK callback for a mouse event in the framebuffer event box: */ | |
74 | +static void | |
75 | +_tme_gtk_mouse_button_down(GtkGesture* self, | |
76 | + int n_press, | |
77 | + gdouble x, | |
78 | + gdouble y, | |
79 | + struct tme_gtk_screen *screen) | |
121 | 80 | { |
122 | - struct tme_gtk_display *display; | |
123 | - int rc; | |
124 | - char *status; | |
125 | - GdkWindow *window; | |
126 | - | |
127 | - /* if this is an enter notify event, grab the focus and continue | |
128 | - propagating the event: */ | |
129 | - if (gdk_event_get_event_type(gdk_event_raw) == GDK_ENTER_NOTIFY) { | |
130 | - gtk_widget_grab_focus(widget); | |
131 | - return (FALSE); | |
132 | - } | |
133 | - | |
134 | - /* if this is not a key press event, continue propagating it now: */ | |
135 | - if (gdk_event_get_event_type(gdk_event_raw) != GDK_KEY_PRESS) { | |
136 | - return (FALSE); | |
137 | - } | |
138 | - | |
139 | - /* recover our data structure: */ | |
140 | - display = screen->screen.tme_screen_display; | |
141 | - | |
142 | - /* lock the mutex: */ | |
143 | - tme_mutex_lock(&display->display.tme_display_mutex); | |
144 | - | |
145 | - /* the mouse must not be on already: */ | |
146 | - assert (screen->tme_gtk_screen_mouse_keyval | |
147 | - == GDK_KEY_VoidSymbol); | |
148 | - | |
149 | - /* this keyval must not be GDK_KEY_VoidSymbol: */ | |
150 | - assert (gdk_event_raw->key.keyval | |
151 | - != GDK_KEY_VoidSymbol); | |
152 | - | |
153 | - /* set the text on the mouse label: */ | |
154 | - gtk_label_set_text(GTK_LABEL(screen->tme_gtk_screen_mouse_label), | |
155 | - _("Mouse is on")); | |
156 | - | |
157 | - /* push the mouse status onto the statusbar: */ | |
158 | - status = NULL; | |
159 | - tme_output_append(&status, | |
160 | - _("Press the %s key to turn the mouse off"), | |
161 | - gdk_keyval_name(gdk_event_raw->key.keyval)); | |
162 | - gtk_statusbar_push(GTK_STATUSBAR(screen->tme_gtk_screen_mouse_statusbar), | |
163 | - screen->tme_gtk_screen_mouse_statusbar_cid, | |
164 | - status); | |
165 | - tme_free(status); | |
166 | - | |
167 | - window = gtk_widget_get_window(screen->tme_gtk_screen_draw); | |
168 | - | |
169 | - /* if the original events mask on the framebuffer event box have | |
170 | - never been saved, save them now, and add the mouse events: */ | |
171 | - /* if (screen->tme_gtk_screen_mouse_events_old == 0) { | |
172 | - screen->tme_gtk_screen_mouse_events_old | |
173 | - = gtk_widget_get_events(screen->tme_gtk_screen_draw); | |
174 | - gtk_widget_add_events(screen->tme_gtk_screen_draw, | |
175 | - GDK_POINTER_MOTION_MASK | |
176 | - | GDK_BUTTON_PRESS_MASK | |
177 | - | GDK_BUTTON_RELEASE_MASK); | |
178 | - } | |
179 | - */ | |
180 | - /* grab the pointer: */ | |
181 | - gtk_grab_add(screen->tme_gtk_screen_draw); | |
182 | - /*gtk_device_grab_add(screen->tme_gtk_screen_draw, | |
183 | - gdk_seat_get_pointer(display->tme_gdk_display_seat), | |
184 | - FALSE);*/ | |
185 | - | |
186 | - rc | |
187 | - = gdk_seat_grab(display->tme_gdk_display_seat, | |
188 | - window, | |
189 | - GDK_SEAT_CAPABILITY_ALL_POINTING, | |
190 | - TRUE, | |
191 | - display->tme_gdk_display_cursor, | |
192 | - gdk_event_raw, | |
193 | - NULL, | |
194 | - NULL); | |
195 | - assert (rc == 0); | |
196 | - | |
197 | - gdk_device_get_position(gdk_seat_get_pointer(display->tme_gdk_display_seat), | |
198 | - NULL, | |
199 | - &display->display.tme_screen_mouse_warp_x, | |
200 | - &display->display.tme_screen_mouse_warp_y); | |
201 | - | |
202 | - /* we are now in mouse mode: */ | |
203 | - screen->tme_gtk_screen_mouse_keyval | |
204 | - = gdk_event_raw->key.keyval; | |
205 | - | |
206 | - /* unlock the mutex: */ | |
207 | - tme_mutex_unlock(&display->display.tme_display_mutex); | |
208 | - | |
209 | - /* stop propagating this event: */ | |
210 | - return (TRUE); | |
81 | + if(screen->tme_gtk_screen_mouse_keyval | |
82 | + != GDK_KEY_VoidSymbol) | |
83 | + _tme_mouse_event(gtk_gesture_single_get_current_button(self), | |
84 | + x, y, screen->screen.tme_screen_display); | |
211 | 85 | } |
212 | 86 | |
213 | -/* this turns mouse mode off. it is called with the mutex locked: */ | |
214 | -void | |
215 | -_tme_gtk_mouse_mode_off(struct tme_gtk_screen *screen, | |
216 | - guint32 time) | |
87 | +/* this is a GTK callback for a mouse event in the framebuffer event box: */ | |
88 | +static void | |
89 | +_tme_gtk_mouse_button_up(GtkGesture* self, | |
90 | + int n_press, | |
91 | + gdouble x, | |
92 | + gdouble y, | |
93 | + struct tme_gtk_screen *screen) | |
217 | 94 | { |
218 | - struct tme_gtk_display *display; | |
219 | - | |
220 | - /* get the display: */ | |
221 | - display = screen->screen.tme_screen_display; | |
222 | - | |
223 | - /* the mouse must be on: */ | |
224 | - assert (screen->tme_gtk_screen_mouse_keyval | |
225 | - != GDK_KEY_VoidSymbol); | |
226 | - | |
227 | - /* ungrab the pointer: */ | |
228 | - gdk_seat_ungrab(display->tme_gdk_display_seat); | |
229 | - gtk_grab_remove(screen->tme_gtk_screen_draw); | |
230 | - //gtk_device_grab_remove(screen->tme_gtk_screen_draw, gdk_seat_get_pointer(display->tme_gdk_display_seat)); | |
231 | - | |
232 | - /* restore the old events mask on the event box: */ | |
233 | - // gtk_widget_set_events(screen->tme_gtk_screen_draw, screen->tme_gtk_screen_mouse_events_old); | |
234 | - | |
235 | - /* pop our message off of the statusbar: */ | |
236 | - gtk_statusbar_pop(GTK_STATUSBAR(screen->tme_gtk_screen_mouse_statusbar), | |
237 | - screen->tme_gtk_screen_mouse_statusbar_cid); | |
238 | - | |
239 | - /* restore the text on the mouse label: */ | |
240 | - gtk_label_set_text(GTK_LABEL(screen->tme_gtk_screen_mouse_label), | |
241 | - _("Mouse is off")); | |
242 | - | |
243 | - /* the mouse is now off: */ | |
244 | - screen->tme_gtk_screen_mouse_keyval = GDK_KEY_VoidSymbol; | |
95 | + if(screen->tme_gtk_screen_mouse_keyval | |
96 | + != GDK_KEY_VoidSymbol) | |
97 | + _tme_mouse_event(-gtk_gesture_single_get_current_button(self), | |
98 | + x, y, screen->screen.tme_screen_display); | |
245 | 99 | } |
246 | 100 | |
247 | 101 | /* this attaches the GTK mouse to a new screen: */ |
248 | 102 | void |
249 | 103 | _tme_gtk_mouse_attach(struct tme_gtk_screen *screen) |
250 | 104 | { |
251 | - GtkWidget *ebox; | |
105 | + GtkEventController *motion, *event; | |
106 | + GtkGesture *press; | |
252 | 107 | |
253 | 108 | /* create the event box for the mouse on label: */ |
254 | - ebox = gtk_event_box_new(); | |
109 | + /* create the mouse on label: */ | |
110 | + screen->tme_gtk_screen_mouse_label | |
111 | + = gtk_frame_new(_("Mouse is off")); | |
255 | 112 | |
256 | 113 | /* pack the event box into the horizontal packing box: */ |
257 | - gtk_header_bar_pack_start(GTK_HEADER_BAR(screen->tme_gtk_screen_header), ebox); | |
114 | + gtk_header_bar_pack_start(GTK_HEADER_BAR(screen->tme_gtk_screen_header), | |
115 | + screen->tme_gtk_screen_mouse_label); | |
258 | 116 | |
117 | +#if GTK_MAJOR_VERSION == 4 | |
118 | + motion=gtk_event_controller_motion_new(); | |
119 | + gtk_widget_add_controller(screen->tme_gtk_screen_draw, motion); | |
120 | + event=gtk_event_controller_motion_new(); | |
121 | + gtk_widget_add_controller(screen->tme_gtk_screen_mouse_label, event); | |
122 | + press = gtk_gesture_click_new(); | |
123 | + gtk_widget_add_controller(screen->tme_gtk_screen_draw, GTK_EVENT_CONTROLLER (press)); | |
124 | +#elif GTK_MAJOR_VERSION == 3 | |
125 | + motion=screen->motion=gtk_event_controller_motion_new(screen->tme_gtk_screen_draw); | |
126 | + event=screen->event=gtk_event_controller_motion_new(screen->tme_gtk_screen_mouse_label); | |
127 | + press=screen->press=gtk_gesture_multi_press_new(screen->tme_gtk_screen_draw); | |
128 | +#endif | |
129 | + | |
130 | + gtk_gesture_single_set_button(GTK_GESTURE_SINGLE (press), 0); | |
259 | 131 | /* set the tip on the event box, which will eventually contain the mouse on label: */ |
260 | - gtk_widget_set_tooltip_text(ebox, | |
132 | + gtk_widget_set_tooltip_text(screen->tme_gtk_screen_mouse_label, | |
261 | 133 | "Press a key here to turn the mouse on. The same key " \ |
262 | 134 | "will turn the mouse off."); |
263 | 135 | |
264 | - /* make sure the event box gets key_press events: */ | |
265 | - gtk_widget_add_events(ebox, | |
266 | - GDK_KEY_PRESS_MASK); | |
267 | - | |
268 | 136 | /* set a signal handler for the event box events: */ |
269 | - g_signal_connect(ebox, | |
137 | + /* g_signal_connect(ebox, | |
270 | 138 | "event", |
271 | 139 | G_CALLBACK(_tme_gtk_mouse_ebox_event), |
272 | - screen); | |
273 | - | |
274 | - /* the event box can focus: */ | |
275 | - gtk_widget_set_can_focus(ebox, TRUE); | |
276 | - | |
277 | - /* create the mouse on label: */ | |
278 | - screen->tme_gtk_screen_mouse_label | |
279 | - = gtk_label_new(_("Mouse is off")); | |
280 | - | |
281 | - /* add the mouse on label to the event box: */ | |
282 | - gtk_container_add(GTK_CONTAINER(ebox), | |
283 | - screen->tme_gtk_screen_mouse_label); | |
140 | + screen); */ | |
284 | 141 | |
285 | 142 | /* create the mouse statusbar: */ |
286 | 143 | screen->tme_gtk_screen_mouse_statusbar |
@@ -298,20 +155,30 @@ _tme_gtk_mouse_attach(struct tme_gtk_screen *screen) | ||
298 | 155 | screen->tme_gtk_screen_mouse_statusbar_cid, |
299 | 156 | _("The Machine Emulator")); |
300 | 157 | |
158 | + /* on entering window, grab keyboard focus: */ | |
159 | + g_signal_connect_swapped(motion, | |
160 | + "enter", | |
161 | + G_CALLBACK(gtk_widget_grab_focus), | |
162 | + screen->tme_gtk_screen_draw); | |
163 | + | |
301 | 164 | /* although the event mask doesn't include these events yet, |
302 | 165 | set a signal handler for the mouse events: */ |
303 | - g_signal_connect(screen->tme_gtk_screen_draw, | |
304 | - "motion_notify_event", | |
305 | - G_CALLBACK(_tme_gtk_mouse_mouse_event), | |
306 | - screen->screen.tme_screen_display); | |
307 | - g_signal_connect(screen->tme_gtk_screen_draw, | |
308 | - "button_press_event", | |
309 | - G_CALLBACK(_tme_gtk_mouse_mouse_event), | |
310 | - screen->screen.tme_screen_display); | |
311 | - g_signal_connect(screen->tme_gtk_screen_draw, | |
312 | - "button_release_event", | |
313 | - G_CALLBACK(_tme_gtk_mouse_mouse_event), | |
314 | - screen->screen.tme_screen_display); | |
166 | + g_signal_connect(motion, | |
167 | + "motion", | |
168 | + G_CALLBACK(_tme_gtk_mouse_motion_event), | |
169 | + screen); | |
170 | + | |
171 | + g_signal_connect(press, "released", G_CALLBACK(_tme_gtk_mouse_button_up), | |
172 | + screen); | |
173 | + | |
174 | + g_signal_connect(press, "pressed", G_CALLBACK(_tme_gtk_mouse_button_down), | |
175 | + screen); | |
176 | + | |
177 | + /* on entering window, grab keyboard focus: */ | |
178 | + g_signal_connect_swapped(event, | |
179 | + "enter", | |
180 | + G_CALLBACK(gtk_widget_grab_focus), | |
181 | + screen->tme_gtk_screen_mouse_label); | |
315 | 182 | |
316 | 183 | /* mouse mode is off: */ |
317 | 184 | screen->tme_gtk_screen_mouse_keyval = GDK_KEY_VoidSymbol; |
@@ -136,7 +136,17 @@ static enum rfbNewClientAction _tme_rfb_newclient(rfbClientPtr cl) | ||
136 | 136 | return RFB_CLIENT_ACCEPT; |
137 | 137 | } |
138 | 138 | |
139 | -static struct tme_display *tme_rfb_display(rfbClientPtr cl) { return cl->clientData; } | |
139 | +static void _tme_mouse_ev(int buttons, int x, int y, rfbClientPtr cl) { | |
140 | + struct tme_display *display = cl->clientData; | |
141 | + | |
142 | + /* make the buttons mask: */ | |
143 | + display->tme_screen_mouse_buttons_last = buttons; | |
144 | + _tme_mouse_event(0,x,y,display); | |
145 | +} | |
146 | + | |
147 | +static void _tme_keyboard_key_ev(int down, tme_keyboard_keyval_t key, rfbClientPtr cl) { | |
148 | + _tme_keyboard_key_event(down, key, cl->clientData); | |
149 | +} | |
140 | 150 | |
141 | 151 | /* the new RFB display function: */ |
142 | 152 | TME_ELEMENT_SUB_NEW_DECL(tme_host_rfb,display) { |
@@ -148,8 +158,6 @@ TME_ELEMENT_SUB_NEW_DECL(tme_host_rfb,display) { | ||
148 | 158 | /* start our data structure: */ |
149 | 159 | tme_display_init(element, 0); |
150 | 160 | |
151 | - _tme_display_get = tme_rfb_display; | |
152 | - | |
153 | 161 | /* recover our data structure: */ |
154 | 162 | display = element->tme_element_private; |
155 | 163 |
@@ -165,8 +173,8 @@ TME_ELEMENT_SUB_NEW_DECL(tme_host_rfb,display) { | ||
165 | 173 | display->tme_screen_height * |
166 | 174 | bpp); |
167 | 175 | server->alwaysShared = TRUE; |
168 | - server->ptrAddEvent = _tme_mouse_buttons_event; | |
169 | - server->kbdAddEvent = _tme_keyboard_key_event; | |
176 | + server->ptrAddEvent = _tme_mouse_ev; | |
177 | + server->kbdAddEvent = _tme_keyboard_key_ev; | |
170 | 178 | server->newClientHook = _tme_rfb_newclient; |
171 | 179 | // server->httpDir = "../webclients"; |
172 | 180 | // server->httpEnableProxyConnect = TRUE; |