summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorOlivier Fourdan <fourdan@xfce.org>2020-12-20 14:12:59 +0100
committerOlivier Fourdan <fourdan@xfce.org>2020-12-21 17:20:17 +0100
commitc697a54ada6d3c915106a061e18f3cf1135b1eef (patch)
tree4bd5e1521ae236de4cfb1a136aa316a1189332e7 /common
parent98abe9250bce568d2775f4e74e7463842ab4a764 (diff)
downloadxfwm4-c697a54ada6d3c915106a061e18f3cf1135b1eef.tar.gz
common: Avoid zero refresh rate for monitor
The function gdk_monitor_get_refresh_rate() can return 0 if there is no real monitor attached (as with Xephyr or VNC for example). The compositor use the value as a divisor to compute the frequency of refresh when zooming, and if the value is 0, xfwm4 will crash with a floating point exception (division by zero error). Make sure we return something even if gdk_monitor_get_refresh_rate() cannot get us a real refresh rate. Signed-off-by: Olivier Fourdan <fourdan@xfce.org>
Diffstat (limited to 'common')
-rw-r--r--common/xfwm-common.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/common/xfwm-common.c b/common/xfwm-common.c
index ce4b30b40..d61c0ec28 100644
--- a/common/xfwm-common.c
+++ b/common/xfwm-common.c
@@ -22,7 +22,7 @@
#include <gdk/gdkx.h>
#include "xfwm-common.h"
-
+#define DEFAULT_REFRESH_RATE 30
void
@@ -140,11 +140,19 @@ xfwm_get_primary_refresh_rate (GdkScreen *screen)
{
GdkDisplay *display;
GdkMonitor *monitor;
+ int refresh_rate;
display = gdk_screen_get_display (screen);
monitor = gdk_display_get_primary_monitor (display);
+ refresh_rate = 0;
+
+ if (monitor)
+ refresh_rate = gdk_monitor_get_refresh_rate (monitor) / 1000;
+
+ if (refresh_rate)
+ return refresh_rate;
- return gdk_monitor_get_refresh_rate (monitor) / 1000;
+ return DEFAULT_REFRESH_RATE;
}