Store monitors-changed handler for disconnection

This commit is contained in:
Jeremie Knuesel 2018-02-16 16:42:33 +01:00
parent 8b93be9471
commit af90d4050d
3 changed files with 14 additions and 7 deletions

View file

@ -230,24 +230,26 @@ cb_monitors_changed(GdkScreen* screen, gpointer data)
}
void
cb_widget_screen_changed(GtkWidget* widget, GdkScreen* UNUSED(previous_screen), gpointer data)
cb_widget_screen_changed(GtkWidget* widget, GdkScreen* previous_screen, gpointer data)
{
girara_debug("signal received");
girara_debug("called");
zathura_t* zathura = data;
if (widget == NULL || zathura == NULL) {
return;
}
/* disconnect previous screen handler if present */
if (previous_screen != NULL && zathura->signals.monitors_changed_handler > 0) {
g_signal_handler_disconnect(previous_screen, zathura->signals.monitors_changed_handler);
zathura->signals.monitors_changed_handler = 0;
}
if (gtk_widget_has_screen(widget)) {
GdkScreen* screen = gtk_widget_get_screen(widget);
/* disconnect signal on previous screen */
g_signal_handlers_disconnect_matched(screen, G_SIGNAL_MATCH_FUNC, 0, 0,
NULL, (gpointer) cb_monitors_changed, zathura);
/* connect to new screen */
g_signal_connect(G_OBJECT(screen),
zathura->signals.monitors_changed_handler = g_signal_connect(G_OBJECT(screen),
"monitors-changed", G_CALLBACK(cb_monitors_changed), zathura);
}

View file

@ -222,6 +222,9 @@ init_ui(zathura_t* zathura)
g_signal_connect(G_OBJECT(zathura->ui.session->gtk.view),
"screen-changed", G_CALLBACK(cb_widget_screen_changed), zathura);
/* initialize the screen-changed handler to 0 (i.e. invalid) */
zathura->signals.monitors_changed_handler = 0;
/* page view */
zathura->ui.page_widget = gtk_grid_new();
gtk_grid_set_row_homogeneous(GTK_GRID(zathura->ui.page_widget), TRUE);

View file

@ -163,6 +163,8 @@ struct zathura_s
#ifdef G_OS_UNIX
guint sigterm;
#endif
gulong monitors_changed_handler; /**< Signal handler for monitors-changed */
} signals;
struct