Skip to content

Commit f2cde20

Browse files
committed
fix select modifier handling
1 parent 5752362 commit f2cde20

File tree

13 files changed

+156
-131
lines changed

13 files changed

+156
-131
lines changed

TODO

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
- row range select breaks after "duplicate"
2-
3-
shift and ctrl click stop affecting select
4-
5-
the keyboard focus is somewhere else, and left-click on rowview
6-
buttons or on workspace background does not grab the focus
7-
81
- maxpos, then create mark from coordinate should be two clicks
92

103
- try:

src/graphicview.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,19 +66,18 @@ void
6666
graphicview_pressed(GtkGestureClick *gesture,
6767
guint n_press, double x, double y, Graphicview *graphicview)
6868
{
69+
Mainwindow *main = MAINWINDOW(view_get_window(VIEW(graphicview)));
70+
6971
if (n_press == 1) {
7072
Rowview *rowview = graphicview_rowview(graphicview);
7173
Row *row = ROW(VOBJECT(rowview)->iobject);
72-
Workspace *ws = row->ws;
7374

74-
row_select_modifier(row, ws->modifiers);
75+
row_select_modifier(row, mainwindow_get_modifiers(main));
7576
}
7677
else {
7778
Model *model = MODEL(VOBJECT(graphicview)->iobject);
78-
GtkWindow *window =
79-
GTK_WINDOW(gtk_widget_get_root(GTK_WIDGET(graphicview)));
8079

81-
model_edit(model, window);
80+
model_edit(model, GTK_WINDOW(main));
8281
}
8382
}
8483

src/gtk/imagewindow.ui

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,13 @@
145145
<property name="default-width">1100</property>
146146
<property name="default-height">1000</property>
147147

148+
<child>
149+
<object class="GtkEventControllerKey">
150+
<signal name="key-pressed" handler="imagewindow_key_pressed"/>
151+
<signal name="key-released" handler="imagewindow_key_released"/>
152+
</object>
153+
</child>
154+
148155
<child type="titlebar">
149156
<object class="GtkHeaderBar" id="header">
150157

src/gtk/mainwindow.ui

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,13 @@
8484
<property name="default-height">800</property>
8585
<signal name="close-request" handler="mainwindow_close_request"/>
8686

87+
<child>
88+
<object class="GtkEventControllerKey">
89+
<signal name="key-pressed" handler="mainwindow_key_pressed"/>
90+
<signal name="key-released" handler="mainwindow_key_released"/>
91+
</object>
92+
</child>
93+
8794
<child type="titlebar">
8895
<object class="GtkHeaderBar" id="header">
8996

src/gtk/workspaceview.ui

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,6 @@
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-
121112
</object>
122113
</child>
123114

src/imageui.c

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,6 @@ struct _Imageui {
133133

134134
gboolean should_animate;
135135

136-
/* We need to detect ctrl-click and shift-click for region create and
137-
* resize.
138-
*
139-
* Windows doesn't seem to support device polling, so we record ctrl and
140-
* shift state here in the keyboard handler.
141-
*/
142-
guint modifiers;
143136
};
144137

145138
G_DEFINE_TYPE(Imageui, imageui, GTK_TYPE_WIDGET);
@@ -969,16 +962,6 @@ imageui_key_pressed(GtkEventControllerKey *self,
969962
handled = FALSE;
970963

971964
switch (keyval) {
972-
case GDK_KEY_Control_L:
973-
case GDK_KEY_Control_R:
974-
imageui->modifiers |= GDK_CONTROL_MASK;
975-
break;
976-
977-
case GDK_KEY_Shift_L:
978-
case GDK_KEY_Shift_R:
979-
imageui->modifiers |= GDK_SHIFT_MASK;
980-
break;
981-
982965
case GDK_KEY_plus:
983966
imageui_magin(imageui);
984967
handled = TRUE;
@@ -1099,16 +1082,6 @@ imageui_key_released(GtkEventControllerKey *self,
10991082
handled = FALSE;
11001083

11011084
switch (keyval) {
1102-
case GDK_KEY_Control_L:
1103-
case GDK_KEY_Control_R:
1104-
imageui->modifiers &= ~GDK_CONTROL_MASK;
1105-
break;
1106-
1107-
case GDK_KEY_Shift_L:
1108-
case GDK_KEY_Shift_R:
1109-
imageui->modifiers &= ~GDK_SHIFT_MASK;
1110-
break;
1111-
11121085
case GDK_KEY_i:
11131086
case GDK_KEY_o:
11141087
imageui->zoom_rate = 1.0;
@@ -1145,6 +1118,7 @@ imageui_drag_begin(GtkEventControllerMotion *self,
11451118
gdouble start_x, gdouble start_y, gpointer user_data)
11461119
{
11471120
Imageui *imageui = IMAGEUI(user_data);
1121+
Imagewindow *win = IMAGEWINDOW(gtk_widget_get_root(GTK_WIDGET(imageui)));
11481122

11491123
Regionview *regionview;
11501124

@@ -1164,7 +1138,7 @@ imageui_drag_begin(GtkEventControllerMotion *self,
11641138
g_object_ref(regionview);
11651139
regionview->start_area = regionview->our_area;
11661140
}
1167-
else if (imageui->modifiers & GDK_CONTROL_MASK) {
1141+
else if (imagewindow_get_modifiers(win) & GDK_CONTROL_MASK) {
11681142
imageui->state = IMAGEUI_CREATE;
11691143
double left;
11701144
double top;
@@ -1206,6 +1180,7 @@ imageui_drag_update(GtkEventControllerMotion *self,
12061180
{
12071181
Imageui *imageui = IMAGEUI(user_data);
12081182
double zoom = imageui_get_zoom(imageui);
1183+
Imagewindow *win = IMAGEWINDOW(gtk_widget_get_root(GTK_WIDGET(imageui)));
12091184

12101185
#ifdef DEBUG_VERBOSE
12111186
printf("imageui_drag_update: offset_x = %g, offset_y = %g\n",
@@ -1220,7 +1195,7 @@ imageui_drag_update(GtkEventControllerMotion *self,
12201195
break;
12211196

12221197
case IMAGEUI_SELECT:
1223-
regionview_resize(imageui->grabbed, imageui->modifiers,
1198+
regionview_resize(imageui->grabbed, imagewindow_get_modifiers(win),
12241199
imageui->tilesource->display_width,
12251200
imageui->tilesource->display_height,
12261201
offset_x / zoom,
@@ -1231,7 +1206,7 @@ imageui_drag_update(GtkEventControllerMotion *self,
12311206
break;
12321207

12331208
case IMAGEUI_CREATE:
1234-
regionview_resize(imageui->floating, imageui->modifiers,
1209+
regionview_resize(imageui->floating, imagewindow_get_modifiers(win),
12351210
imageui->tilesource->display_width,
12361211
imageui->tilesource->display_height,
12371212
offset_x / zoom,

src/imagewindow.c

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,14 @@ struct _Imagewindow {
124124
View *action_view;
125125

126126
GSettings *settings;
127+
128+
/* We need to detect ctrl-click and shift-click for region create and
129+
* resize.
130+
*
131+
* Windows doesn't seem to support device polling, so we record ctrl and
132+
* shift state here in a keyboard handler.
133+
*/
134+
guint modifiers;
127135
};
128136

129137
G_DEFINE_TYPE(Imagewindow, imagewindow, GTK_TYPE_APPLICATION_WINDOW);
@@ -1423,6 +1431,60 @@ imagewindow_pressed(GtkGestureClick *gesture,
14231431
gtk_popover_popup(GTK_POPOVER(menu));
14241432
}
14251433

1434+
static gboolean
1435+
imagewindow_key_pressed(GtkEventControllerKey *self,
1436+
guint keyval, guint keycode, GdkModifierType state, gpointer user_data)
1437+
{
1438+
Imagewindow *win = IMAGEWINDOW(user_data);
1439+
1440+
switch (keyval) {
1441+
case GDK_KEY_Control_L:
1442+
case GDK_KEY_Control_R:
1443+
win->modifiers |= GDK_CONTROL_MASK;
1444+
break;
1445+
1446+
case GDK_KEY_Shift_L:
1447+
case GDK_KEY_Shift_R:
1448+
win->modifiers |= GDK_SHIFT_MASK;
1449+
break;
1450+
1451+
default:
1452+
break;
1453+
}
1454+
1455+
return FALSE;
1456+
}
1457+
1458+
static gboolean
1459+
imagewindow_key_released(GtkEventControllerKey *self,
1460+
guint keyval, guint keycode, GdkModifierType state, gpointer user_data)
1461+
{
1462+
Imagewindow *win = IMAGEWINDOW(user_data);
1463+
1464+
switch (keyval) {
1465+
case GDK_KEY_Control_L:
1466+
case GDK_KEY_Control_R:
1467+
win->modifiers &= ~GDK_CONTROL_MASK;
1468+
break;
1469+
1470+
case GDK_KEY_Shift_L:
1471+
case GDK_KEY_Shift_R:
1472+
win->modifiers &= ~GDK_SHIFT_MASK;
1473+
break;
1474+
1475+
default:
1476+
break;
1477+
}
1478+
1479+
return FALSE;
1480+
}
1481+
1482+
guint
1483+
imagewindow_get_modifiers(Imagewindow *win)
1484+
{
1485+
return win->modifiers;
1486+
}
1487+
14261488
static void
14271489
imagewindow_class_init(ImagewindowClass *class)
14281490
{
@@ -1445,6 +1507,8 @@ imagewindow_class_init(ImagewindowClass *class)
14451507

14461508
BIND_CALLBACK(imagewindow_pressed);
14471509
BIND_CALLBACK(imagewindow_error_clicked);
1510+
BIND_CALLBACK(imagewindow_key_pressed);
1511+
BIND_CALLBACK(imagewindow_key_released);
14481512

14491513
gobject_class->dispose = imagewindow_dispose;
14501514

src/imagewindow.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ void imagewindow_get_mouse_position(Imagewindow *win,
5353
Tilesource *imagewindow_get_tilesource(Imagewindow *win);
5454
GtkWidget *imagewindow_get_main_box(Imagewindow *win);
5555
GSettings *imagewindow_get_settings(Imagewindow *win);
56+
guint imagewindow_get_modifiers(Imagewindow *win);
5657

5758
void imagewindow_set_iimage(Imagewindow *win, iImage *iimage);
5859

src/mainwindow.c

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,14 @@ struct _Mainwindow {
6060
/* Store things like toolkit menu visibility in gsettings.
6161
*/
6262
GSettings *settings;
63+
64+
/* We need to detect ctrl-click and shift-click for range selecting.
65+
*
66+
* Windows doesn't seem to support device polling, so we record ctrl and
67+
* shift state here in the keyboard handler.
68+
*/
69+
guint modifiers;
70+
6371
};
6472

6573
// current autocalc state
@@ -723,6 +731,60 @@ mainwindow_close_request(GtkWindow *self, gpointer user_data)
723731
return FALSE;
724732
}
725733

734+
static gboolean
735+
mainwindow_key_pressed(GtkEventControllerKey *self,
736+
guint keyval, guint keycode, GdkModifierType state, gpointer user_data)
737+
{
738+
Mainwindow *main = MAINWINDOW(user_data);
739+
740+
switch (keyval) {
741+
case GDK_KEY_Control_L:
742+
case GDK_KEY_Control_R:
743+
main->modifiers |= GDK_CONTROL_MASK;
744+
break;
745+
746+
case GDK_KEY_Shift_L:
747+
case GDK_KEY_Shift_R:
748+
main->modifiers |= GDK_SHIFT_MASK;
749+
break;
750+
751+
default:
752+
break;
753+
}
754+
755+
return FALSE;
756+
}
757+
758+
static gboolean
759+
mainwindow_key_released(GtkEventControllerKey *self,
760+
guint keyval, guint keycode, GdkModifierType state, gpointer user_data)
761+
{
762+
Mainwindow *main = MAINWINDOW(user_data);
763+
764+
switch (keyval) {
765+
case GDK_KEY_Control_L:
766+
case GDK_KEY_Control_R:
767+
main->modifiers &= ~GDK_CONTROL_MASK;
768+
break;
769+
770+
case GDK_KEY_Shift_L:
771+
case GDK_KEY_Shift_R:
772+
main->modifiers &= ~GDK_SHIFT_MASK;
773+
break;
774+
775+
default:
776+
break;
777+
}
778+
779+
return FALSE;
780+
}
781+
782+
guint
783+
mainwindow_get_modifiers(Mainwindow *main)
784+
{
785+
return main->modifiers;
786+
}
787+
726788
static void
727789
mainwindow_class_init(MainwindowClass *class)
728790
{
@@ -740,6 +802,8 @@ mainwindow_class_init(MainwindowClass *class)
740802

741803
BIND_CALLBACK(mainwindow_progress_cancel_clicked);
742804
BIND_CALLBACK(mainwindow_close_request);
805+
BIND_CALLBACK(mainwindow_key_pressed);
806+
BIND_CALLBACK(mainwindow_key_released);
743807
}
744808

745809
static void

src/mainwindow.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ void mainwindow_about(Mainwindow *main, VipsBuf *buf);
5454
gboolean mainwindow_is_empty(Mainwindow *main);
5555
GtkWindow *mainwindow_pick_one(void);
5656

57+
guint mainwindow_get_modifiers(Mainwindow *main);
58+
5759
GSettings *mainwindow_get_settings(GtkWidget *widget);
5860

5961
#endif /* __MAINWINDOW_H */

0 commit comments

Comments
 (0)