Skip to content

Commit 619f817

Browse files
committed
try to save pane position
hmmmm though it's not working
1 parent 58231df commit 619f817

File tree

4 files changed

+60
-39
lines changed

4 files changed

+60
-39
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,9 @@ then check the build status here:
242242
and improve the default position ... should be the width of the
243243
properties widget
244244

245-
- on props hide, force kb focus to iamgedisplay
245+
- on props hide, force kb focus to imagedisplay?
246+
247+
how can we tell if a child of $widget has the focus?
246248

247249
- use eg. alt-left, alt-right to flip between images in "vipsdisp a.jpg b.jpg"
248250
or maybe shift-<, shift->?

org.libvips.vipsdisp.gschema.xml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,15 @@
2727
<default>false</default>
2828
<summary>Show Properties menu</summary>
2929
<description>
30-
If set, show the Properties menu.
30+
If set, show the Properties pane.
31+
</description>
32+
</key>
33+
34+
<key type="i" name="properties-position">
35+
<default>500</default>
36+
<summary>Properties pane divider position</summary>
37+
<description>
38+
Position of the properties pane divider.
3139
</description>
3240
</key>
3341

src/animatedpane.c

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,23 @@
11
/*
2-
#define DEBUG
32
*/
3+
#define DEBUG
44

55
#include "vipsdisp.h"
66

77
/* Duration of the GtkPaned enter/leave animations
88
*/
99
#define PANED_DURATION (0.5)
1010

11-
/* The initial position of the GtkPaned separator. When revealed, the
12-
* child needs to be visible even on the smallest displays. We don't want
13-
* users to just see the separator on the far right of the window, since it
14-
* might not be obvious what it is.
15-
*/
16-
#define INITIAL_PANED_POSITION (200)
17-
1811
struct _Animatedpane
1912
{
2013
GtkWidget parent_instance;
2114

2215
GtkWidget *paned;
2316

24-
// the state we expose via properties
17+
// right hand pane is visible
2518
gboolean revealed;
19+
20+
// distance of the divider from the RIGHT edge of the window
2621
int position;
2722

2823
// animation state.
@@ -113,12 +108,18 @@ animatedpaned_set_child_visibility( Animatedpane *animatedpane,
113108
gtk_widget_show( child );
114109
else
115110
gtk_widget_hide( child );
111+
116112
}
117113

118114
static void
119115
animatedpaned_set_child_position( Animatedpane *animatedpane, int position )
120116
{
121-
gtk_paned_set_position( GTK_PANED( animatedpane->paned ), position );
117+
// our position is distance from the right edge -- we must swap this
118+
int widget_width = gtk_widget_get_width( GTK_WIDGET( animatedpane ) );
119+
int paned_position = widget_width - position;
120+
121+
gtk_paned_set_position( GTK_PANED( animatedpane->paned ),
122+
paned_position );
122123
}
123124

124125
/* From clutter-easing.c, based on Robert Penner's infamous easing equations,
@@ -144,9 +145,9 @@ animatedpane_animate_tick( GtkWidget *widget, GdkFrameClock *frame_clock,
144145
gint64 dt = animatedpane->last_frame_time > 0 ?
145146
frame_time - animatedpane->last_frame_time :
146147
0;
148+
animatedpane->last_frame_time = frame_time;
147149

148150
animatedpane->elapsed += (double) dt / G_TIME_SPAN_SECOND;
149-
animatedpane->last_frame_time = frame_time;
150151

151152
t = ease_out_cubic( animatedpane->elapsed / PANED_DURATION );
152153

@@ -189,16 +190,10 @@ animatedpaned_set_revealed( Animatedpane *animatedpane, gboolean revealed )
189190
animatedpane->elapsed = 0.0;
190191
animatedpane->is_animating = TRUE;
191192

192-
if( revealed ) {
193-
animatedpane->start =
194-
gtk_widget_get_width( GTK_WIDGET( animatedpane ) );
195-
animatedpane->stop = animatedpane->position;
196-
}
197-
else {
198-
animatedpane->start = animatedpane->position;
199-
animatedpane->stop =
200-
gtk_widget_get_width( GTK_WIDGET( animatedpane ) );
201-
}
193+
animatedpane->start = animatedpane->position;
194+
animatedpane->stop = 0;
195+
if( revealed )
196+
VIPS_SWAP( int, animatedpane->start, animatedpane->stop );
202197

203198
animatedpaned_set_child_position( animatedpane,
204199
animatedpane->start );
@@ -208,10 +203,9 @@ animatedpaned_set_revealed( Animatedpane *animatedpane, gboolean revealed )
208203

209204
gtk_widget_add_tick_callback( GTK_WIDGET( animatedpane ),
210205
animatedpane_animate_tick, NULL, NULL );
211-
}
212-
else {
213-
animatedpaned_set_child_visibility( animatedpane, revealed );
214206
}
207+
else
208+
animatedpaned_set_child_visibility( animatedpane, revealed );
215209
}
216210
}
217211

@@ -257,12 +251,14 @@ animatedpane_set_property( GObject *object,
257251
}
258252
#endif /*DEBUG*/
259253

260-
// no need to implement set_position, the notify callback from the paned
261-
// will do it
262-
263254
if( prop_id == PROP_REVEALED )
264255
animatedpaned_set_revealed( animatedpane,
265256
g_value_get_boolean( value ) );
257+
else if( prop_id == PROP_POSITION ) {
258+
animatedpane->position = g_value_get_int( value );
259+
animatedpaned_set_child_position( animatedpane,
260+
animatedpane->position );
261+
}
266262
else if( prop_id < PROP_REVEALED )
267263
g_object_set_property( G_OBJECT( animatedpane->paned ),
268264
prop_names[prop_id], value );
@@ -313,12 +309,18 @@ animatedpane_position_notify( GtkWidget *paned,
313309
if( animatedpane->revealed &&
314310
!animatedpane->is_animating ) {
315311
// FIXME ... could get from pspec?
316-
animatedpane->position = gtk_paned_get_position( GTK_PANED( paned ) );
312+
int paned_position = gtk_paned_get_position( GTK_PANED( paned ) );
313+
314+
// our position is distance from the right edge -- we must swap this
315+
int widget_width = gtk_widget_get_width( GTK_WIDGET( animatedpane ) );
316+
int position = widget_width - paned_position;
317317

318318
#ifdef DEBUG
319-
printf( "animatedpane_position_notify: new position %d\n",
320-
animatedpane->position );
319+
printf( "animatedpane_position_notify: new position %d\n", position );
321320
#endif /* DEBUG */
321+
322+
if( animatedpane->position != position )
323+
g_object_set( animatedpane, "position", position, NULL );
322324
}
323325
}
324326

@@ -329,7 +331,8 @@ animatedpane_init( Animatedpane *animatedpane )
329331
printf( "animatedpane_init:\n" );
330332
#endif /*DEBUG*/
331333

332-
animatedpane->position = INITIAL_PANED_POSITION;
334+
// distance of the divider from the RIGHT edge of the window
335+
animatedpane->position = 500;
333336

334337
// it'd be nice to create our gtkpaned in animatedpane.ui, but we need
335338
// this pointer during builder

src/imagewindow.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,7 @@ image_window_duplicate_action( GSimpleAction *action,
522522
copy_state( GTK_WIDGET( new ), GTK_WIDGET( win ), "control" );
523523
copy_state( GTK_WIDGET( new ), GTK_WIDGET( win ), "info" );
524524
copy_state( GTK_WIDGET( new ), GTK_WIDGET( win ), "properties" );
525+
copy_state( GTK_WIDGET( new ), GTK_WIDGET( win ), "properties-position" );
525526
copy_state( GTK_WIDGET( new ), GTK_WIDGET( win ), "background" );
526527

527528
/* We want to init the scroll position, but we can't do that until the
@@ -1585,6 +1586,18 @@ image_window_init( ImageWindow *win )
15851586
"revealed",
15861587
G_SETTINGS_BIND_DEFAULT );
15871588

1589+
g_settings_bind( win->settings, "properties-position",
1590+
G_OBJECT( win->properties_pane ),
1591+
"position",
1592+
G_SETTINGS_BIND_DEFAULT );
1593+
1594+
/* Initialise from settings.
1595+
*/
1596+
change_state( GTK_WIDGET( win ), "properties",
1597+
g_settings_get_value( win->settings, "properties" ) );
1598+
change_state( GTK_WIDGET( win ), "properties-position",
1599+
g_settings_get_value( win->settings, "properties-position" ) );
1600+
15881601
/* Initial menu state from settings.
15891602
*/
15901603
change_state( GTK_WIDGET( win ), "control",
@@ -1758,7 +1771,7 @@ image_window_open( ImageWindow *win, GFile *file )
17581771
TileSource *tile_source;
17591772

17601773
#ifdef DEBUG
1761-
puts( "image_window_open" );
1774+
printf( "image_window_open:\n" );
17621775
#endif /* DEBUG */
17631776

17641777
path = g_file_get_path( file );
@@ -1769,11 +1782,6 @@ image_window_open( ImageWindow *win, GFile *file )
17691782
return;
17701783
}
17711784

1772-
/* Re-initialize from settings.
1773-
*/
1774-
change_state( GTK_WIDGET( win ), "properties",
1775-
g_settings_get_value( win->settings, "properties" ) );
1776-
17771785
image_window_set_tile_source( win, tile_source );
17781786

17791787
g_object_unref( tile_source );

0 commit comments

Comments
 (0)