Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
pwmt
zathura
Commits
fc5a344d
Commit
fc5a344d
authored
Feb 11, 2018
by
Jeremie Knuesel
Browse files
Use signals to detect DPI change
parent
553a8ff4
Changes
3
Hide whitespace changes
Inline
Side-by-side
zathura/callbacks.c
View file @
fc5a344d
...
...
@@ -216,6 +216,44 @@ cb_refresh_view(GtkWidget* GIRARA_UNUSED(view), gpointer data)
statusbar_page_number_update
(
zathura
);
}
void
cb_monitors_changed
(
GdkScreen
*
screen
,
gpointer
data
)
{
girara_debug
(
"signal received"
);
zathura_t
*
zathura
=
data
;
if
(
screen
==
NULL
||
zathura
==
NULL
)
{
return
;
}
zathura_update_view_dpi
(
zathura
);
}
void
cb_widget_screen_changed
(
GtkWidget
*
widget
,
GdkScreen
*
UNUSED
(
previous_screen
),
gpointer
data
)
{
girara_debug
(
"signal received"
);
zathura_t
*
zathura
=
data
;
if
(
widget
==
NULL
||
zathura
==
NULL
)
{
return
;
}
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
),
"monitors-changed"
,
G_CALLBACK
(
cb_monitors_changed
),
zathura
);
}
zathura_update_view_dpi
(
zathura
);
}
void
cb_scale_factor
(
GObject
*
object
,
GParamSpec
*
UNUSED
(
pspec
),
gpointer
data
)
{
...
...
@@ -235,6 +273,7 @@ cb_scale_factor(GObject* object, GParamSpec* UNUSED(pspec), gpointer data)
fabs
(
new_factor
-
current
.
y
)
>=
DBL_EPSILON
)
{
zathura_document_set_device_factors
(
zathura
->
document
,
new_factor
,
new_factor
);
girara_debug
(
"New device scale factor: %d"
,
new_factor
);
zathura_update_view_dpi
(
zathura
);
render_all
(
zathura
);
}
}
...
...
zathura/callbacks.h
View file @
fc5a344d
...
...
@@ -79,6 +79,30 @@ void cb_view_vadjustment_changed(GtkAdjustment *adjustment, gpointer data);
*/
void
cb_refresh_view
(
GtkWidget
*
view
,
gpointer
data
);
/**
* This function gets called when the monitors associated with the GdkScreen
* change.
*
* It udpates the stored value for the monitor DPI.
*
* @param screen The GDK screen
* @param gpointer The zathura instance
*/
void
cb_monitors_changed
(
GdkScreen
*
screen
,
gpointer
data
);
/**
* This function gets called when the screen associated with the view widget
* changes.
*
* It udpates updates the connection on the monitors-changed ignal and the
* stored value for the monitor DPI.
*
* @param widget The view widget
* @param previous_screen The widget's previous screen
* @param gpointer The zathura instance
*/
void
cb_widget_screen_changed
(
GtkWidget
*
widget
,
GdkScreen
*
previous_screen
,
gpointer
data
);
/**
* This function gets called when the view widget scale factor changes (e.g.
* when moving from a regular to a HiDPI screen).
...
...
zathura/zathura.c
View file @
fc5a344d
...
...
@@ -217,6 +217,9 @@ init_ui(zathura_t* zathura)
g_signal_connect
(
G_OBJECT
(
zathura
->
ui
.
session
->
gtk
.
view
),
"notify::scale-factor"
,
G_CALLBACK
(
cb_scale_factor
),
zathura
);
g_signal_connect
(
G_OBJECT
(
zathura
->
ui
.
session
->
gtk
.
view
),
"screen-changed"
,
G_CALLBACK
(
cb_widget_screen_changed
),
zathura
);
/* page view */
zathura
->
ui
.
page_widget
=
gtk_grid_new
();
gtk_grid_set_row_homogeneous
(
GTK_GRID
(
zathura
->
ui
.
page_widget
),
TRUE
);
...
...
@@ -1025,6 +1028,9 @@ document_open(zathura_t* zathura, const char* path, const char* uri, const char*
zathura_update_view_dpi
(
zathura
);
/* call screen-changed callback to connect monitors-changed signal on initial screen */
cb_widget_screen_changed
(
zathura
->
ui
.
session
->
gtk
.
view
,
NULL
,
zathura
);
/* get initial device scale */
int
device_factor
=
gtk_widget_get_scale_factor
(
zathura
->
ui
.
session
->
gtk
.
view
);
zathura_document_set_device_factors
(
zathura
->
document
,
device_factor
,
device_factor
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment