Skip to content

Commit 98b7130

Browse files
committed
disconnect/reconnect displaybar on image change
1 parent f1bbe71 commit 98b7130

File tree

6 files changed

+78
-25
lines changed

6 files changed

+78
-25
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,10 @@ On success, merge to master.
230230

231231
## TODO
232232

233+
- duplicate could copy zoom/pan settings
234+
235+
- next image twice ... display bar stops working
236+
233237
- get `object_unref: assertion 'G_IS_OBJECT (object)' failed` during free of
234238
stack ... seems to be a harmless minor glib bug with `g_clear_object()`
235239
failing with a crit for a null value
@@ -244,8 +248,6 @@ On success, merge to master.
244248
- looks like duplicate of a texture view will fail ... see
245249
tile_source_duplicate()
246250

247-
- next / prev image does not set scale offset etc
248-
249251
- check mem use, esp with three large images loaded
250252

251253
- PDF page change does not change image size if pages vary in size

src/displaybar.c

Lines changed: 51 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,22 @@ struct _Displaybar {
1212
*/
1313
ImageWindow *win;
1414

15+
/* The tile_source we are currently controlling. Not a ref.
16+
*/
17+
TileSource *tile_source;
18+
1519
GtkWidget *action_bar;
1620
GtkWidget *gears;
1721
GtkWidget *page;
1822
GtkWidget *scale;
1923
GtkWidget *offset;
24+
25+
/* We have to disconnect and reconnect these when imagewindow gets a new
26+
* tile_source.
27+
*/
28+
guint changed_sid;
29+
guint tiles_changed_sid;
30+
guint page_changed_sid;
2031
};
2132

2233
G_DEFINE_TYPE(Displaybar, displaybar, GTK_TYPE_WIDGET);
@@ -32,8 +43,8 @@ static void
3243
displaybar_tile_source_changed(TileSource *tile_source, Displaybar *displaybar)
3344
{
3445
#ifdef DEBUG
35-
printf("displaybar_tile_source_changed:\n");
3646
#endif /*DEBUG*/
47+
printf("displaybar_tile_source_changed:\n");
3748

3849
if (TSLIDER(displaybar->scale)->value != tile_source->scale) {
3950
TSLIDER(displaybar->scale)->value = tile_source->scale;
@@ -63,23 +74,45 @@ displaybar_page_changed(TileSource *tile_source, Displaybar *displaybar)
6374
tile_source->page);
6475
}
6576

77+
static void
78+
displaybar_disconnect(Displaybar *displaybar)
79+
{
80+
if (displaybar->tile_source) {
81+
FREESID(displaybar->changed_sid, displaybar->tile_source);
82+
FREESID(displaybar->tiles_changed_sid, displaybar->tile_source);
83+
FREESID(displaybar->page_changed_sid, displaybar->tile_source);
84+
85+
displaybar->tile_source = NULL;
86+
}
87+
}
88+
6689
/* Imagewindow has a new tile_source.
6790
*/
6891
static void
6992
displaybar_image_window_changed(ImageWindow *win, Displaybar *displaybar)
7093
{
71-
TileSource *tile_source;
94+
TileSource *tile_source = image_window_get_tile_source(win);
95+
96+
#ifdef DEBUG
97+
#endif /*DEBUG*/
98+
printf("displaybar_image_window_changed:\n");
99+
100+
displaybar_disconnect(displaybar);
101+
102+
if (tile_source) {
103+
displaybar->changed_sid = g_signal_connect(tile_source,
104+
"changed",
105+
G_CALLBACK(displaybar_tile_source_changed), displaybar);
106+
displaybar->tiles_changed_sid = g_signal_connect(tile_source,
107+
"tiles-changed",
108+
G_CALLBACK(displaybar_tile_source_changed), displaybar);
109+
displaybar->page_changed_sid = g_signal_connect(tile_source,
110+
"page-changed",
111+
G_CALLBACK(displaybar_page_changed), displaybar);
72112

73-
if ((tile_source = image_window_get_tile_source(win))) {
74-
g_signal_connect_object(tile_source, "changed",
75-
G_CALLBACK(displaybar_tile_source_changed),
76-
displaybar, 0);
77-
g_signal_connect_object(tile_source, "tiles-changed",
78-
G_CALLBACK(displaybar_tile_source_changed),
79-
displaybar, 0);
80-
g_signal_connect_object(tile_source, "page-changed",
81-
G_CALLBACK(displaybar_page_changed),
82-
displaybar, 0);
113+
displaybar->tile_source = tile_source;
114+
115+
displaybar_tile_source_changed(tile_source, displaybar);
83116
}
84117
}
85118

@@ -89,6 +122,7 @@ displaybar_set_image_window(Displaybar *displaybar, ImageWindow *win)
89122
/* No need to ref ... win holds a ref to us.
90123
*/
91124
displaybar->win = win;
125+
displaybar->tile_source = image_window_get_tile_source(win);
92126

93127
g_signal_connect_object(win, "changed",
94128
G_CALLBACK(displaybar_image_window_changed),
@@ -150,6 +184,8 @@ displaybar_dispose(GObject *object)
150184
printf("displaybar_dispose:\n");
151185
#endif /*DEBUG*/
152186

187+
displaybar_disconnect(displaybar);
188+
153189
VIPS_FREEF(gtk_widget_unparent, displaybar->action_bar);
154190

155191
G_OBJECT_CLASS(displaybar_parent_class)->dispose(object);
@@ -159,7 +195,7 @@ static void
159195
displaybar_page_value_changed(GtkSpinButton *spin_button,
160196
Displaybar *displaybar)
161197
{
162-
TileSource *tile_source = image_window_get_tile_source(displaybar->win);
198+
TileSource *tile_source = displaybar->tile_source;
163199
int new_page = gtk_spin_button_get_value_as_int(spin_button);
164200

165201
#ifdef DEBUG
@@ -175,7 +211,7 @@ displaybar_page_value_changed(GtkSpinButton *spin_button,
175211
static void
176212
displaybar_scale_value_changed(Tslider *slider, Displaybar *displaybar)
177213
{
178-
TileSource *tile_source = image_window_get_tile_source(displaybar->win);
214+
TileSource *tile_source = displaybar->tile_source;
179215

180216
if (tile_source)
181217
g_object_set(tile_source,
@@ -186,7 +222,7 @@ displaybar_scale_value_changed(Tslider *slider, Displaybar *displaybar)
186222
static void
187223
displaybar_offset_value_changed(Tslider *slider, Displaybar *displaybar)
188224
{
189-
TileSource *tile_source = image_window_get_tile_source(displaybar->win);
225+
TileSource *tile_source = displaybar->tile_source;
190226

191227
if (tile_source)
192228
g_object_set(tile_source,

src/gtk/imagewindow.ui

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,6 @@
1313
<attribute name="action">win.paste</attribute>
1414
<attribute name="verb-icon">edit-paste-symbolic</attribute>
1515
</item>
16-
<item>
17-
<attribute name="label">Reload</attribute>
18-
<attribute name="action">win.reload</attribute>
19-
<attribute name="verb-icon">view-refresh-symbolic</attribute>
20-
</item>
2116
<item>
2217
<attribute name="label">Fullscreen</attribute>
2318
<attribute name="action">win.fullscreen</attribute>
@@ -33,6 +28,11 @@
3328
<attribute name="action">win.next</attribute>
3429
<attribute name="verb-icon">go-next-symbolic</attribute>
3530
</item>
31+
<item>
32+
<attribute name="label">Reload</attribute>
33+
<attribute name="action">win.reload</attribute>
34+
<attribute name="verb-icon">view-refresh-symbolic</attribute>
35+
</item>
3636
</section>
3737

3838
<section>

src/imagewindow.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -643,14 +643,16 @@ image_window_imageui_set_visible(ImageWindow *win,
643643
"active", g_variant_get_boolean(control),
644644
"visible", TRUE,
645645
NULL);
646-
647-
//tile_source_changed(new_tile_source);
648646
}
649647

650648
// not a ref, so we can just overwrite it
651649
win->imageui = imageui;
652650

651+
// update the displaybar etc.
653652
image_window_changed(win);
653+
654+
// update the menus
655+
image_window_tile_source_changed(new_tile_source, win);
654656
}
655657

656658
static void
@@ -998,7 +1000,8 @@ image_window_duplicate_action(GSimpleAction *action,
9981000

9991001
if (win->imageui) {
10001002
TileSource *tile_source = imageui_get_tile_source(win->imageui);
1001-
TileSource *new_tile_source = tile_source_duplicate(tile_source);
1003+
g_autoptr(TileSource) new_tile_source =
1004+
tile_source_duplicate(tile_source);
10021005
Imageui *imageui = imageui_new(new_tile_source);
10031006

10041007
image_window_imageui_add(new_win, imageui);

src/tilesource.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1887,6 +1887,7 @@ tile_source_duplicate(TileSource *tile_source)
18871887
"falsecolour", &falsecolour,
18881888
"log", &log,
18891889
"icc", &icc,
1890+
"active", &active,
18901891
NULL);
18911892

18921893
g_object_set(new_tile_source,
@@ -1897,6 +1898,7 @@ tile_source_duplicate(TileSource *tile_source)
18971898
"falsecolour", falsecolour,
18981899
"log", log,
18991900
"icc", icc,
1901+
"active", active,
19001902
NULL);
19011903

19021904
return new_tile_source;

src/vipsdisp.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,16 @@
3232
*/
3333
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
3434

35+
#define FREESID(SID, OBJ) \
36+
G_STMT_START \
37+
{ \
38+
if ((SID) && (OBJ)) { \
39+
g_signal_handler_disconnect((OBJ), (SID)); \
40+
(SID) = 0; \
41+
} \
42+
} \
43+
G_STMT_END
44+
3545
#include "gtkutil.h"
3646
#include "tslider.h"
3747
#include "vipsdispapp.h"

0 commit comments

Comments
 (0)