Revision | 9b2874cb656f72b34151c30c067dc3b5cf87bd9f (tree) |
---|---|
Time | 2023-04-02 21:00:45 |
Author | phabrics <phabrics@phab...> |
Commiter | phabrics |
Removal of deprecated status bar in favor of a switch/entry combo for mouse toggling.
@@ -84,8 +84,12 @@ typedef struct tme_gtk_screen { | ||
84 | 84 | GtkWidget *tme_gtk_screen_draw; |
85 | 85 | cairo_surface_t *tme_gtk_screen_surface; |
86 | 86 | |
87 | - /* the mouse on label: */ | |
87 | + /* the mouse label: */ | |
88 | 88 | GtkWidget *tme_gtk_screen_mouse_label; |
89 | + /* the mouse toggle button: */ | |
90 | + GtkWidget *tme_gtk_screen_mouse_button; | |
91 | + /* the name of the mouse toggle key: */ | |
92 | + GtkWidget *tme_gtk_screen_mouse_key; | |
89 | 93 | |
90 | 94 | /* if GDK_VoidSymbol, mouse mode is off. otherwise, |
91 | 95 | mouse mode is on, and this is the keyval that will |
@@ -93,10 +97,6 @@ typedef struct tme_gtk_screen { | ||
93 | 97 | guint tme_gtk_screen_mouse_keyval; |
94 | 98 | |
95 | 99 | #if GTK_MAJOR_VERSION == 3 |
96 | - /* the status bar, and the context ID: */ | |
97 | - GtkWidget *tme_gtk_screen_mouse_statusbar; | |
98 | - guint tme_gtk_screen_mouse_statusbar_cid; | |
99 | - | |
100 | 100 | cairo_format_t tme_gtk_screen_format; |
101 | 101 | GtkEventController *key, *mouse, *motion, *event; |
102 | 102 | GtkGesture *press; |
@@ -56,16 +56,7 @@ _tme_gtk_keyboard_key_down( | ||
56 | 56 | != keyval) |
57 | 57 | return _tme_keyboard_key_event(TRUE, keyval, screen->screen.tme_screen_display); |
58 | 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; | |
59 | + gtk_switch_set_active(GTK_SWITCH(screen->tme_gtk_screen_mouse_button), FALSE); | |
69 | 60 | |
70 | 61 | return (TRUE); |
71 | 62 |
@@ -98,30 +89,11 @@ _tme_gtk_mouse_key_down( | ||
98 | 89 | /* recover our data structure: */ |
99 | 90 | display = screen->screen.tme_screen_display; |
100 | 91 | |
101 | - if(screen->tme_gtk_screen_mouse_keyval | |
102 | - != GDK_KEY_VoidSymbol) return (FALSE); | |
103 | - | |
104 | 92 | /* lock the mutex: */ |
105 | 93 | tme_mutex_lock(&display->display.tme_display_mutex); |
106 | 94 | |
107 | - /* this keyval must not be GDK_KEY_VoidSymbol: */ | |
108 | - assert (keyval | |
109 | - != GDK_KEY_VoidSymbol); | |
95 | + gtk_entry_set_text(GTK_ENTRY(screen->tme_gtk_screen_mouse_key), gdk_keyval_name(keyval)); | |
110 | 96 | |
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 | 97 | gdk_device_get_position(gdk_seat_get_pointer(display->tme_gdk_display_seat), |
126 | 98 | NULL, |
127 | 99 | &display->display.tme_screen_mouse_warp_x, |
@@ -131,6 +103,8 @@ _tme_gtk_mouse_key_down( | ||
131 | 103 | screen->tme_gtk_screen_mouse_keyval |
132 | 104 | = keyval; |
133 | 105 | |
106 | + gtk_widget_grab_focus(screen->tme_gtk_screen_draw); | |
107 | + | |
134 | 108 | /* unlock the mutex: */ |
135 | 109 | tme_mutex_unlock(&display->display.tme_display_mutex); |
136 | 110 |
@@ -146,15 +120,13 @@ _tme_gtk_keyboard_attach(struct tme_gtk_screen *screen) | ||
146 | 120 | #if GTK_MAJOR_VERSION == 4 |
147 | 121 | key=gtk_event_controller_key_new(); |
148 | 122 | gtk_widget_add_controller(screen->tme_gtk_screen_draw, key); |
149 | - gtk_widget_set_focussable(screen->tme_gtk_screen_draw, TRUE); | |
123 | + gtk_widget_set_focusable(screen->tme_gtk_screen_draw, TRUE); | |
150 | 124 | 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); | |
125 | + gtk_widget_add_controller(screen->tme_gtk_screen_mouse_key, mouse); | |
153 | 126 | #elif GTK_MAJOR_VERSION == 3 |
154 | 127 | key=screen->key=gtk_event_controller_key_new(screen->tme_gtk_screen_draw); |
155 | 128 | 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); | |
129 | + mouse=screen->mouse=gtk_event_controller_key_new(screen->tme_gtk_screen_mouse_key); | |
158 | 130 | #endif |
159 | 131 | |
160 | 132 | g_signal_connect_after(key, |
@@ -167,10 +139,9 @@ _tme_gtk_keyboard_attach(struct tme_gtk_screen *screen) | ||
167 | 139 | G_CALLBACK(_tme_gtk_keyboard_key_up), |
168 | 140 | screen); |
169 | 141 | |
170 | - g_signal_connect_after(mouse, | |
171 | - "key-pressed", | |
172 | - G_CALLBACK(_tme_gtk_mouse_key_down), | |
173 | - screen); | |
142 | + g_signal_connect(mouse, | |
143 | + "key-pressed", | |
144 | + G_CALLBACK(_tme_gtk_mouse_key_down), | |
145 | + screen); | |
174 | 146 | |
175 | 147 | } |
176 | - |
@@ -65,8 +65,7 @@ _tme_gtk_mouse_motion_event(GtkEventControllerMotion* self, | ||
65 | 65 | struct tme_gtk_screen *screen) |
66 | 66 | |
67 | 67 | { |
68 | - if(screen->tme_gtk_screen_mouse_keyval | |
69 | - != GDK_KEY_VoidSymbol) | |
68 | + if(gtk_switch_get_state(GTK_SWITCH(screen->tme_gtk_screen_mouse_button))) | |
70 | 69 | _tme_mouse_event(0, x, y, screen->screen.tme_screen_display); |
71 | 70 | } |
72 | 71 |
@@ -78,8 +77,7 @@ _tme_gtk_mouse_button_down(GtkGesture* self, | ||
78 | 77 | gdouble y, |
79 | 78 | struct tme_gtk_screen *screen) |
80 | 79 | { |
81 | - if(screen->tme_gtk_screen_mouse_keyval | |
82 | - != GDK_KEY_VoidSymbol) | |
80 | + if(gtk_switch_get_state(GTK_SWITCH(screen->tme_gtk_screen_mouse_button))) | |
83 | 81 | _tme_mouse_event(gtk_gesture_single_get_current_button(self), |
84 | 82 | x, y, screen->screen.tme_screen_display); |
85 | 83 | } |
@@ -92,8 +90,7 @@ _tme_gtk_mouse_button_up(GtkGesture* self, | ||
92 | 90 | gdouble y, |
93 | 91 | struct tme_gtk_screen *screen) |
94 | 92 | { |
95 | - if(screen->tme_gtk_screen_mouse_keyval | |
96 | - != GDK_KEY_VoidSymbol) | |
93 | + if(gtk_switch_get_state(GTK_SWITCH(screen->tme_gtk_screen_mouse_button))) | |
97 | 94 | _tme_mouse_event(-gtk_gesture_single_get_current_button(self), |
98 | 95 | x, y, screen->screen.tme_screen_display); |
99 | 96 | } |
@@ -105,57 +102,35 @@ _tme_gtk_mouse_attach(struct tme_gtk_screen *screen) | ||
105 | 102 | GtkEventController *motion, *event; |
106 | 103 | GtkGesture *press; |
107 | 104 | |
108 | - /* create the event box for the mouse on label: */ | |
109 | - /* create the mouse on label: */ | |
110 | - screen->tme_gtk_screen_mouse_label | |
111 | - = gtk_frame_new(_("Mouse is off")); | |
105 | + /* create the mouse label, button, and key: */ | |
106 | + screen->tme_gtk_screen_mouse_label = gtk_label_new(_("Mouse Mode")); | |
107 | + screen->tme_gtk_screen_mouse_button = gtk_switch_new(); | |
108 | + // = gtk_toggle_button_new_with_label(_("Mouse Mode")); | |
109 | + screen->tme_gtk_screen_mouse_key = gtk_entry_new(); | |
112 | 110 | |
113 | - /* pack the event box into the horizontal packing box: */ | |
114 | 111 | gtk_header_bar_pack_start(GTK_HEADER_BAR(screen->tme_gtk_screen_header), |
115 | 112 | screen->tme_gtk_screen_mouse_label); |
113 | + gtk_header_bar_pack_start(GTK_HEADER_BAR(screen->tme_gtk_screen_header), | |
114 | + screen->tme_gtk_screen_mouse_button); | |
115 | + gtk_header_bar_pack_start(GTK_HEADER_BAR(screen->tme_gtk_screen_header), | |
116 | + screen->tme_gtk_screen_mouse_key); | |
116 | 117 | |
117 | 118 | #if GTK_MAJOR_VERSION == 4 |
118 | 119 | motion=gtk_event_controller_motion_new(); |
119 | 120 | 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 | 121 | press = gtk_gesture_click_new(); |
123 | 122 | gtk_widget_add_controller(screen->tme_gtk_screen_draw, GTK_EVENT_CONTROLLER (press)); |
124 | 123 | #elif GTK_MAJOR_VERSION == 3 |
125 | 124 | 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 | 125 | press=screen->press=gtk_gesture_multi_press_new(screen->tme_gtk_screen_draw); |
128 | 126 | #endif |
129 | 127 | |
130 | 128 | gtk_gesture_single_set_button(GTK_GESTURE_SINGLE (press), 0); |
131 | - /* set the tip on the event box, which will eventually contain the mouse on label: */ | |
132 | - gtk_widget_set_tooltip_text(screen->tme_gtk_screen_mouse_label, | |
129 | + /* set the tip on the entry box: */ | |
130 | + gtk_widget_set_tooltip_text(screen->tme_gtk_screen_mouse_key, | |
133 | 131 | "Press a key here to turn the mouse on. The same key " \ |
134 | 132 | "will turn the mouse off."); |
135 | 133 | |
136 | - /* set a signal handler for the event box events: */ | |
137 | - /* g_signal_connect(ebox, | |
138 | - "event", | |
139 | - G_CALLBACK(_tme_gtk_mouse_ebox_event), | |
140 | - screen); */ | |
141 | - | |
142 | - /* create the mouse statusbar: */ | |
143 | - screen->tme_gtk_screen_mouse_statusbar | |
144 | - = gtk_statusbar_new(); | |
145 | - | |
146 | - /* pack the mouse statusbar into the horizontal packing box: */ | |
147 | - gtk_header_bar_pack_start(GTK_HEADER_BAR(screen->tme_gtk_screen_header), | |
148 | - screen->tme_gtk_screen_mouse_statusbar); | |
149 | - | |
150 | - /* push an initial message onto the statusbar: */ | |
151 | - screen->tme_gtk_screen_mouse_statusbar_cid | |
152 | - = gtk_statusbar_get_context_id(GTK_STATUSBAR(screen->tme_gtk_screen_mouse_statusbar), | |
153 | - "mouse context"); | |
154 | - gtk_statusbar_push(GTK_STATUSBAR(screen->tme_gtk_screen_mouse_statusbar), | |
155 | - screen->tme_gtk_screen_mouse_statusbar_cid, | |
156 | - _("The Machine Emulator")); | |
157 | - | |
158 | - /* on entering window, grab keyboard focus: */ | |
159 | 134 | g_signal_connect_swapped(motion, |
160 | 135 | "enter", |
161 | 136 | G_CALLBACK(gtk_widget_grab_focus), |
@@ -174,12 +149,6 @@ _tme_gtk_mouse_attach(struct tme_gtk_screen *screen) | ||
174 | 149 | g_signal_connect(press, "pressed", G_CALLBACK(_tme_gtk_mouse_button_down), |
175 | 150 | screen); |
176 | 151 | |
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); | |
182 | - | |
183 | 152 | /* mouse mode is off: */ |
184 | 153 | screen->tme_gtk_screen_mouse_keyval = GDK_KEY_VoidSymbol; |
185 | 154 | } |