Skip to content

Commit 9764e8f

Browse files
committed
fix ctrl/shift detect on win
1 parent fe6be6e commit 9764e8f

File tree

10 files changed

+127
-24
lines changed

10 files changed

+127
-24
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
## master
22

3+
- fix ctrl/shift detect on windows
4+
35
## 9.0.6 2025/04/16
46

57
- fix perspective distort

TODO

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
- toolkit menu: return to home by default, have a temp "pin in place" toggle
2+
at the top right to stop it
3+
4+
- pin in place disables if you click "back"
5+
6+
- ctrl-drag / ctrl-click to make region / mark does not work on windows
7+
18
- fix scRGB with alpha
29

310
- "reset" in display bar resets the position of scale/offset widgets, but does

src/graphicview.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ graphicview_pressed(GtkGestureClick *gesture,
6969
if (n_press == 1) {
7070
Rowview *rowview = graphicview_rowview(graphicview);
7171
Row *row = ROW(VOBJECT(rowview)->iobject);
72-
guint state = get_modifiers(GTK_EVENT_CONTROLLER(gesture));
72+
Workspace *ws = row->ws;
7373

74-
row_select_modifier(row, state);
74+
row_select_modifier(row, ws->modifiers);
7575
}
7676
else {
7777
Model *model = MODEL(VOBJECT(graphicview)->iobject);

src/gtk/workspaceview.ui

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,15 @@
109109
</object>
110110
</child>
111111

112+
<child>
113+
<object class="GtkEventControllerKey">
114+
<signal name="key-pressed"
115+
handler="workspaceview_key_pressed"/>
116+
<signal name="key-released"
117+
handler="workspaceview_key_released"/>
118+
</object>
119+
</child>
120+
112121
</object>
113122
</child>
114123

src/gtkutil.c

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -279,17 +279,6 @@ get_dpi(void)
279279
return 72;
280280
}
281281

282-
guint
283-
get_modifiers(GtkEventController *controller)
284-
{
285-
GdkDevice *mouse_device =
286-
gtk_event_controller_get_current_event_device(controller);
287-
GdkSeat *seat = gdk_device_get_seat(mouse_device);
288-
GdkDevice *keyboard_device = gdk_seat_get_keyboard(seat);
289-
290-
return gdk_device_get_modifier_state(keyboard_device);
291-
}
292-
293282
static void
294283
alert_yesno_cb(GObject *source_object,
295284
GAsyncResult *result, gpointer user_data)

src/gtkutil.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ void action_radio(GSimpleAction *action,
8585
GVariant *parameter, gpointer user_data);
8686

8787
int get_dpi(void);
88-
guint get_modifiers(GtkEventController *controller);
8988

9089
G_DEFINE_AUTOPTR_CLEANUP_FUNC(cairo_t, cairo_destroy)
9190
G_DEFINE_AUTOPTR_CLEANUP_FUNC(cairo_surface_t, cairo_surface_destroy)

src/imageui.c

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,15 @@ struct _Imageui {
128128
gint64 last_frame_time;
129129

130130
gboolean should_animate;
131+
132+
/* We need to detect ctrl-click and shift-click for region create and
133+
* resize.
134+
*
135+
* Windows doesn't seem to support device polling, so we record ctrl and
136+
* shift state here in the keyboard handler.
137+
*/
138+
guint modifiers;
139+
131140
};
132141

133142
G_DEFINE_TYPE(Imageui, imageui, GTK_TYPE_WIDGET);
@@ -820,6 +829,16 @@ imageui_key_pressed(GtkEventControllerKey *self,
820829
handled = FALSE;
821830

822831
switch (keyval) {
832+
case GDK_KEY_Control_L:
833+
case GDK_KEY_Control_R:
834+
imageui->modifiers |= GDK_CONTROL_MASK;
835+
break;
836+
837+
case GDK_KEY_Shift_L:
838+
case GDK_KEY_Shift_R:
839+
imageui->modifiers |= GDK_SHIFT_MASK;
840+
break;
841+
823842
case GDK_KEY_plus:
824843
imageui_magin(imageui);
825844
handled = TRUE;
@@ -940,6 +959,16 @@ imageui_key_released(GtkEventControllerKey *self,
940959
handled = FALSE;
941960

942961
switch (keyval) {
962+
case GDK_KEY_Control_L:
963+
case GDK_KEY_Control_R:
964+
imageui->modifiers &= ~GDK_CONTROL_MASK;
965+
break;
966+
967+
case GDK_KEY_Shift_L:
968+
case GDK_KEY_Shift_R:
969+
imageui->modifiers &= ~GDK_SHIFT_MASK;
970+
break;
971+
943972
case GDK_KEY_i:
944973
case GDK_KEY_o:
945974
imageui->zoom_rate = 1.0;
@@ -977,7 +1006,6 @@ imageui_drag_begin(GtkEventControllerMotion *self,
9771006
{
9781007
Imageui *imageui = IMAGEUI(user_data);
9791008

980-
guint modifiers;
9811009
Regionview *regionview;
9821010

9831011
#ifdef DEBUG_VERBOSE
@@ -987,7 +1015,6 @@ imageui_drag_begin(GtkEventControllerMotion *self,
9871015

9881016
switch (imageui->state) {
9891017
case IMAGEUI_WAIT:
990-
modifiers = get_modifiers(GTK_EVENT_CONTROLLER(self));
9911018
regionview = imageui_find_regionview(imageui, start_x, start_y);
9921019

9931020
if (regionview) {
@@ -997,7 +1024,7 @@ imageui_drag_begin(GtkEventControllerMotion *self,
9971024
g_object_ref(regionview);
9981025
regionview->start_area = regionview->our_area;
9991026
}
1000-
else if (modifiers & GDK_CONTROL_MASK) {
1027+
else if (imageui->modifiers & GDK_CONTROL_MASK) {
10011028
imageui->state = IMAGEUI_CREATE;
10021029
double left;
10031030
double top;
@@ -1039,7 +1066,6 @@ imageui_drag_update(GtkEventControllerMotion *self,
10391066
{
10401067
Imageui *imageui = IMAGEUI(user_data);
10411068
double zoom = imageui_get_zoom(imageui);
1042-
guint modifiers = get_modifiers(GTK_EVENT_CONTROLLER(self));
10431069

10441070
#ifdef DEBUG_VERBOSE
10451071
printf("imageui_drag_update: offset_x = %g, offset_y = %g\n",
@@ -1054,7 +1080,7 @@ imageui_drag_update(GtkEventControllerMotion *self,
10541080
break;
10551081

10561082
case IMAGEUI_SELECT:
1057-
regionview_resize(imageui->grabbed, modifiers,
1083+
regionview_resize(imageui->grabbed, imageui->modifiers,
10581084
imageui->tilesource->display_width,
10591085
imageui->tilesource->display_height,
10601086
offset_x / zoom,
@@ -1065,7 +1091,7 @@ imageui_drag_update(GtkEventControllerMotion *self,
10651091
break;
10661092

10671093
case IMAGEUI_CREATE:
1068-
regionview_resize(imageui->floating, modifiers,
1094+
regionview_resize(imageui->floating, imageui->modifiers,
10691095
imageui->tilesource->display_width,
10701096
imageui->tilesource->display_height,
10711097
offset_x / zoom,

src/rowview.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ rowview_pressed(GtkGestureClick *gesture,
284284
guint n_press, double x, double y, Rowview *rview)
285285
{
286286
Row *row = ROW(VOBJECT(rview)->iobject);
287+
Workspace *ws = row->ws;
287288

288289
if (n_press == 1) {
289290
if (row->err &&
@@ -292,10 +293,7 @@ rowview_pressed(GtkGestureClick *gesture,
292293
// click on a row with an error displays the error
293294
workspace_set_show_error(row->ws, TRUE);
294295

295-
// select handling ... do this for rows with errors too
296-
guint state = get_modifiers(GTK_EVENT_CONTROLLER(gesture));
297-
298-
row_select_modifier(row, state);
296+
row_select_modifier(row, ws->modifiers);
299297
}
300298
else
301299
rowview_edit(rview);

src/workspace.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,14 @@ struct _Workspace {
103103
*/
104104
gboolean needs_layout;
105105
gboolean in_dispose;
106+
107+
/* We need to detect ctrl-click and shift-click for row toggle select and
108+
* extend select.
109+
*
110+
* Windows doesn't seem to support device polling, so we record ctrl and
111+
* shift state here in the keyboard handler.
112+
*/
113+
guint modifiers;
106114
};
107115

108116
typedef struct _WorkspaceClass {

src/workspaceview.c

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1247,6 +1247,69 @@ workspaceview_error_close_clicked(GtkButton *button, void *user_data)
12471247
workspace_set_show_error(ws, FALSE);
12481248
}
12491249

1250+
static gboolean
1251+
workspaceview_key_pressed(GtkEventControllerKey *self,
1252+
guint keyval, guint keycode, GdkModifierType state, gpointer user_data)
1253+
{
1254+
Workspaceview *wview = WORKSPACEVIEW(user_data);
1255+
Workspace *ws = WORKSPACE(VOBJECT(wview)->iobject);
1256+
1257+
gboolean handled;
1258+
1259+
#ifdef DEBUG_VERBOSE
1260+
#endif /*DEBUG_VERBOSE*/
1261+
printf("workspaceview_key_pressed: keyval = %d, state = %d\n",
1262+
keyval, state);
1263+
1264+
handled = FALSE;
1265+
1266+
switch (keyval) {
1267+
case GDK_KEY_Control_L:
1268+
case GDK_KEY_Control_R:
1269+
ws->modifiers |= GDK_CONTROL_MASK;
1270+
break;
1271+
1272+
case GDK_KEY_Shift_L:
1273+
case GDK_KEY_Shift_R:
1274+
ws->modifiers |= GDK_SHIFT_MASK;
1275+
break;
1276+
1277+
default:
1278+
break;
1279+
}
1280+
1281+
return handled;
1282+
}
1283+
1284+
static gboolean
1285+
workspaceview_key_released(GtkEventControllerKey *self,
1286+
guint keyval, guint keycode, GdkModifierType state, gpointer user_data)
1287+
{
1288+
Workspaceview *wview = WORKSPACEVIEW(user_data);
1289+
Workspace *ws = WORKSPACE(VOBJECT(wview)->iobject);
1290+
1291+
gboolean handled;
1292+
1293+
handled = FALSE;
1294+
1295+
switch (keyval) {
1296+
case GDK_KEY_Control_L:
1297+
case GDK_KEY_Control_R:
1298+
ws->modifiers &= ~GDK_CONTROL_MASK;
1299+
break;
1300+
1301+
case GDK_KEY_Shift_L:
1302+
case GDK_KEY_Shift_R:
1303+
ws->modifiers &= ~GDK_SHIFT_MASK;
1304+
break;
1305+
1306+
default:
1307+
break;
1308+
}
1309+
1310+
return handled;
1311+
}
1312+
12501313
static void
12511314
workspaceview_class_init(WorkspaceviewClass *class)
12521315
{
@@ -1273,6 +1336,8 @@ workspaceview_class_init(WorkspaceviewClass *class)
12731336
BIND_CALLBACK(workspaceview_drag_update);
12741337
BIND_CALLBACK(workspaceview_drag_end);
12751338
BIND_CALLBACK(workspaceview_error_close_clicked);
1339+
BIND_CALLBACK(workspaceview_key_pressed);
1340+
BIND_CALLBACK(workspaceview_key_released);
12761341

12771342
object_class->dispose = workspaceview_dispose;
12781343

0 commit comments

Comments
 (0)