Skip to content

Commit 7bf6884

Browse files
committed
better focus handling on props hide
1 parent d803c74 commit 7bf6884

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

README.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -237,10 +237,6 @@ then check the build status here:
237237

238238
## TODO
239239

240-
- on props hide, force kb focus to imagedisplay?
241-
242-
how can we tell if a child of $widget has the focus?
243-
244240
- use eg. alt-left, alt-right to flip between images in "vipsdisp a.jpg b.jpg"
245241
or maybe shift-<, shift->?
246242

src/imagewindow.c

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1423,19 +1423,19 @@ image_window_properties( GSimpleAction *action,
14231423
GVariant *state, gpointer user_data )
14241424
{
14251425
ImageWindow *win = VIPSDISP_IMAGE_WINDOW( user_data );
1426+
gboolean revealed = g_variant_get_boolean( state );
14261427

14271428
#ifdef DEBUG
14281429
puts("image_window_properties");
14291430
#endif /* DEBUG */
14301431

14311432
g_object_set( win->properties_pane,
1432-
"revealed", g_variant_get_boolean( state ),
1433+
"revealed", revealed,
14331434
NULL );
14341435

14351436
g_simple_action_set_state( action, state );
14361437
}
14371438

1438-
14391439
static GActionEntry image_window_entries[] = {
14401440
{ "magin", image_window_magin_action },
14411441
{ "magout", image_window_magout_action },
@@ -1470,6 +1470,23 @@ static GActionEntry image_window_entries[] = {
14701470
{ "reset", image_window_reset },
14711471
};
14721472

1473+
static void
1474+
image_window_properties_leave( GtkEventControllerFocus *self,
1475+
gpointer user_data )
1476+
{
1477+
ImageWindow *win = VIPSDISP_IMAGE_WINDOW( user_data );
1478+
1479+
gboolean revealed;
1480+
1481+
g_object_get( win->properties_pane,
1482+
"revealed", &revealed,
1483+
NULL );
1484+
1485+
// if the props pane had the focus, and it's being hidden, we must refocus
1486+
if( !revealed )
1487+
gtk_widget_grab_focus( win->imagedisplay );
1488+
}
1489+
14731490
static void
14741491
image_window_init( ImageWindow *win )
14751492
{
@@ -1546,6 +1563,14 @@ image_window_init( ImageWindow *win )
15461563
G_CALLBACK( image_window_drag_update ), win );
15471564
gtk_widget_add_controller( win->imagedisplay, controller );
15481565

1566+
/* We need to know if the props pane has the focus so we can refocus on
1567+
* hide.
1568+
*/
1569+
controller = GTK_EVENT_CONTROLLER( gtk_event_controller_focus_new() );
1570+
g_signal_connect( controller, "leave",
1571+
G_CALLBACK( image_window_properties_leave ), win );
1572+
gtk_widget_add_controller( win->properties, controller );
1573+
15491574
g_settings_bind( win->settings, "control",
15501575
G_OBJECT( win->display_bar ),
15511576
"revealed",

0 commit comments

Comments
 (0)