1*4882a593SmuzhiyunFrom 8bd80ba5d98890bb18270ab94d4c18ab010c6b2e Mon Sep 17 00:00:00 2001
2*4882a593SmuzhiyunFrom: Jeffy Chen <jeffy.chen@rock-chips.com>
3*4882a593SmuzhiyunDate: Fri, 5 Jul 2019 15:16:42 +0800
4*4882a593SmuzhiyunSubject: [PATCH 1/3] Support limiting move interval
5*4882a593Smuzhiyun
6*4882a593SmuzhiyunSet "moveInterval" in the rc.xml's resize section, eg.
7*4882a593Smuzhiyun<moveInterval>50</moveInterval> to limit move interval.
8*4882a593Smuzhiyun
9*4882a593SmuzhiyunSigned-off-by: Jeffy Chen <jeffy.chen@rock-chips.com>
10*4882a593Smuzhiyun---
11*4882a593Smuzhiyun openbox/config.c     |  4 ++++
12*4882a593Smuzhiyun openbox/config.h     |  2 ++
13*4882a593Smuzhiyun openbox/moveresize.c | 37 +++++++++++++++++++++++++++++++++++--
14*4882a593Smuzhiyun 3 files changed, 41 insertions(+), 2 deletions(-)
15*4882a593Smuzhiyun
16*4882a593Smuzhiyundiff --git a/openbox/config.c b/openbox/config.c
17*4882a593Smuzhiyunindex dad5d1bf..d5129bc6 100644
18*4882a593Smuzhiyun--- a/openbox/config.c
19*4882a593Smuzhiyun+++ b/openbox/config.c
20*4882a593Smuzhiyun@@ -65,6 +65,7 @@ GSList *config_desktops_names;
21*4882a593Smuzhiyun guint   config_screen_firstdesk;
22*4882a593Smuzhiyun guint   config_desktop_popup_time;
23*4882a593Smuzhiyun
24*4882a593Smuzhiyun+gboolean         config_move_interval;
25*4882a593Smuzhiyun gboolean         config_resize_redraw;
26*4882a593Smuzhiyun gint             config_resize_popup_show;
27*4882a593Smuzhiyun ObResizePopupPos config_resize_popup_pos;
28*4882a593Smuzhiyun@@ -820,6 +821,8 @@ static void parse_resize(xmlNodePtr node, gpointer d)
29*4882a593Smuzhiyun
30*4882a593Smuzhiyun     node = node->children;
31*4882a593Smuzhiyun
32*4882a593Smuzhiyun+    if ((n = obt_xml_find_node(node, "moveInterval")))
33*4882a593Smuzhiyun+        config_move_interval = obt_xml_node_int(n);
34*4882a593Smuzhiyun     if ((n = obt_xml_find_node(node, "drawContents")))
35*4882a593Smuzhiyun         config_resize_redraw = obt_xml_node_bool(n);
36*4882a593Smuzhiyun     if ((n = obt_xml_find_node(node, "popupShow"))) {
37*4882a593Smuzhiyun@@ -1115,6 +1118,7 @@ void config_startup(ObtXmlInst *i)
38*4882a593Smuzhiyun
39*4882a593Smuzhiyun     obt_xml_register(i, "desktops", parse_desktops, NULL);
40*4882a593Smuzhiyun
41*4882a593Smuzhiyun+    config_move_interval = 16; /* default is 16 ms(60fps) */
42*4882a593Smuzhiyun     config_resize_redraw = TRUE;
43*4882a593Smuzhiyun     config_resize_popup_show = 1; /* nonpixel increments */
44*4882a593Smuzhiyun     config_resize_popup_pos = OB_RESIZE_POS_CENTER;
45*4882a593Smuzhiyundiff --git a/openbox/config.h b/openbox/config.h
46*4882a593Smuzhiyunindex 96a66cf1..59447b2d 100644
47*4882a593Smuzhiyun--- a/openbox/config.h
48*4882a593Smuzhiyun+++ b/openbox/config.h
49*4882a593Smuzhiyun@@ -103,6 +103,8 @@ extern ObPlaceMonitor config_primary_monitor;
50*4882a593Smuzhiyun /*! User-specified margins around the edge of the screen(s) */
51*4882a593Smuzhiyun extern StrutPartial config_margins;
52*4882a593Smuzhiyun
53*4882a593Smuzhiyun+/*! duration(ms) to perform moving */
54*4882a593Smuzhiyun+extern gboolean config_move_interval;
55*4882a593Smuzhiyun /*! When true windows' contents are refreshed while they are resized; otherwise
56*4882a593Smuzhiyun   they are not updated until the resize is complete */
57*4882a593Smuzhiyun extern gboolean config_resize_redraw;
58*4882a593Smuzhiyundiff --git a/openbox/moveresize.c b/openbox/moveresize.c
59*4882a593Smuzhiyunindex d12a64de..0a301caf 100644
60*4882a593Smuzhiyun--- a/openbox/moveresize.c
61*4882a593Smuzhiyun+++ b/openbox/moveresize.c
62*4882a593Smuzhiyun@@ -68,6 +68,8 @@ static guint waiting_for_sync;
63*4882a593Smuzhiyun #ifdef SYNC
64*4882a593Smuzhiyun static guint sync_timer = 0;
65*4882a593Smuzhiyun #endif
66*4882a593Smuzhiyun+static glong last_move_time = 0;
67*4882a593Smuzhiyun+static guint move_timer = 0;
68*4882a593Smuzhiyun
69*4882a593Smuzhiyun static ObPopup *popup = NULL;
70*4882a593Smuzhiyun
71*4882a593Smuzhiyun@@ -328,6 +330,9 @@ void moveresize_end(gboolean cancel)
72*4882a593Smuzhiyun         if (sync_timer) g_source_remove(sync_timer);
73*4882a593Smuzhiyun         sync_timer = 0;
74*4882a593Smuzhiyun #endif
75*4882a593Smuzhiyun+    } else {
76*4882a593Smuzhiyun+        if (move_timer) g_source_remove(move_timer);
77*4882a593Smuzhiyun+        move_timer = 0;
78*4882a593Smuzhiyun     }
79*4882a593Smuzhiyun
80*4882a593Smuzhiyun     /* don't use client_move() here, use the same width/height as
81*4882a593Smuzhiyun@@ -370,6 +375,15 @@ void moveresize_end(gboolean cancel)
82*4882a593Smuzhiyun     moveresize_client = NULL;
83*4882a593Smuzhiyun }
84*4882a593Smuzhiyun
85*4882a593Smuzhiyun+static gboolean move_func(gpointer data)
86*4882a593Smuzhiyun+{
87*4882a593Smuzhiyun+    client_configure(moveresize_client, cur_x, cur_y, cur_w, cur_h,
88*4882a593Smuzhiyun+                     TRUE, FALSE, FALSE);
89*4882a593Smuzhiyun+
90*4882a593Smuzhiyun+    move_timer = 0;
91*4882a593Smuzhiyun+    return FALSE; /* don't repeat */
92*4882a593Smuzhiyun+}
93*4882a593Smuzhiyun+
94*4882a593Smuzhiyun static void do_move(gboolean keyboard, gint keydist)
95*4882a593Smuzhiyun {
96*4882a593Smuzhiyun     gint resist;
97*4882a593Smuzhiyun@@ -380,8 +394,27 @@ static void do_move(gboolean keyboard, gint keydist)
98*4882a593Smuzhiyun     if (!keyboard) resist = config_resist_edge;
99*4882a593Smuzhiyun     resist_move_monitors(moveresize_client, resist, &cur_x, &cur_y);
100*4882a593Smuzhiyun
101*4882a593Smuzhiyun-    client_configure(moveresize_client, cur_x, cur_y, cur_w, cur_h,
102*4882a593Smuzhiyun-                     TRUE, FALSE, FALSE);
103*4882a593Smuzhiyun+    if (!config_move_interval) {
104*4882a593Smuzhiyun+        client_configure(moveresize_client, cur_x, cur_y, cur_w, cur_h,
105*4882a593Smuzhiyun+                         TRUE, FALSE, FALSE);
106*4882a593Smuzhiyun+    } else if (!move_timer) {
107*4882a593Smuzhiyun+        GTimeVal curr_tm;
108*4882a593Smuzhiyun+        glong now_ms, next_ms;
109*4882a593Smuzhiyun+
110*4882a593Smuzhiyun+        g_get_current_time(&curr_tm);
111*4882a593Smuzhiyun+        now_ms = curr_tm.tv_sec * 1000 + curr_tm.tv_usec / 1000;
112*4882a593Smuzhiyun+        next_ms = last_move_time + config_move_interval;
113*4882a593Smuzhiyun+
114*4882a593Smuzhiyun+        if (next_ms <= now_ms) {
115*4882a593Smuzhiyun+            client_configure(moveresize_client, cur_x, cur_y, cur_w, cur_h,
116*4882a593Smuzhiyun+                             TRUE, FALSE, FALSE);
117*4882a593Smuzhiyun+            last_move_time = now_ms;
118*4882a593Smuzhiyun+        } else {
119*4882a593Smuzhiyun+            move_timer = g_timeout_add(config_move_interval, move_func, NULL);
120*4882a593Smuzhiyun+            last_move_time = next_ms;
121*4882a593Smuzhiyun+        }
122*4882a593Smuzhiyun+    }
123*4882a593Smuzhiyun+
124*4882a593Smuzhiyun     if (config_resize_popup_show == 2) /* == "Always" */
125*4882a593Smuzhiyun         popup_coords(moveresize_client, "%d x %d",
126*4882a593Smuzhiyun                      moveresize_client->frame->area.x,
127*4882a593Smuzhiyun--
128*4882a593Smuzhiyun2.17.1
129*4882a593Smuzhiyun
130