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