Browse Source

xwindow_translate_for_gravity: Change instead of set argument

Previously, this function overwrote the value of its argument with the
result. After this change, the function merely changes the given
variable by the calculated argument.

Thus, the old behaviour is achieved by setting the variable to zero
before the call, which all callers already did. However, for most
callers this change means that a temporary variable can be removed and
instead xwindow_translate_for_gravity() will directly change the target
variable.

No change in behaviour intended.

Signed-off-by: Uli Schlachter <psychon@znc.in>
Uli Schlachter 1 year ago
parent
commit
21b7b29630
3 changed files with 8 additions and 18 deletions
  1. 2
    6
      event.c
  2. 2
    8
      objects/client.c
  3. 4
    4
      xwindow.c

+ 2
- 6
event.c View File

@@ -345,17 +345,13 @@ event_handle_configurerequest(xcb_configure_request_event_t *ev)
345 345
 
346 346
         if(ev->value_mask & XCB_CONFIG_WINDOW_X)
347 347
         {
348
-            int16_t diff = 0;
349 348
             geometry.x = ev->x;
350
-            xwindow_translate_for_gravity(c->size_hints.win_gravity, deco_left, 0, deco_right, 0, &diff, NULL);
351
-            geometry.x += diff;
349
+            xwindow_translate_for_gravity(c->size_hints.win_gravity, deco_left, 0, deco_right, 0, &geometry.x, NULL);
352 350
         }
353 351
         if(ev->value_mask & XCB_CONFIG_WINDOW_Y)
354 352
         {
355
-            int16_t diff = 0;
356 353
             geometry.y = ev->y;
357
-            xwindow_translate_for_gravity(c->size_hints.win_gravity, 0, deco_top, 0, deco_bottom, NULL, &diff);
358
-            geometry.y += diff;
354
+            xwindow_translate_for_gravity(c->size_hints.win_gravity, 0, deco_top, 0, deco_bottom, NULL, &geometry.y);
359 355
         }
360 356
         if(ev->value_mask & XCB_CONFIG_WINDOW_WIDTH)
361 357
         {

+ 2
- 8
objects/client.c View File

@@ -1387,12 +1387,9 @@ border_width_callback(client_t *c, uint16_t old_width, uint16_t new_width)
1387 1387
     {
1388 1388
         area_t geometry = c->geometry;
1389 1389
         int16_t diff = new_width - old_width;
1390
-        int16_t diff_x = 0, diff_y = 0;
1391 1390
         xwindow_translate_for_gravity(c->size_hints.win_gravity,
1392 1391
                                       diff, diff, diff, diff,
1393
-                                      &diff_x, &diff_y);
1394
-        geometry.x += diff_x;
1395
-        geometry.y += diff_y;
1392
+                                      &geometry.x, &geometry.y);
1396 1393
         /* inform client about changes */
1397 1394
         client_resize_do(c, geometry);
1398 1395
     }
@@ -2870,13 +2867,10 @@ titlebar_resize(lua_State *L, int cidx, client_t *c, client_titlebar_t bar, int
2870 2867
 
2871 2868
     if(c->size_hints.flags & XCB_ICCCM_SIZE_HINT_P_WIN_GRAVITY)
2872 2869
     {
2873
-        int16_t diff_x = 0, diff_y = 0;
2874 2870
         xwindow_translate_for_gravity(c->size_hints.win_gravity,
2875 2871
                                       diff_left, diff_top,
2876 2872
                                       diff_right, diff_bottom,
2877
-                                      &diff_x, &diff_y);
2878
-        geometry.x += diff_x;
2879
-        geometry.y += diff_y;
2873
+                                      &geometry.x, &geometry.y);
2880 2874
     }
2881 2875
 
2882 2876
     c->titlebar[bar].size = size;

+ 4
- 4
xwindow.c View File

@@ -400,8 +400,8 @@ xwindow_set_shape(xcb_window_t win, int width, int height, enum xcb_shape_sk_t k
400 400
  * \param change_height_before The window height difference that will be applied.
401 401
  * \param change_width_after The window width difference that will be applied.
402 402
  * \param change_height_after The window height difference that will be applied.
403
- * \param dx On return, this will be set to the amount the pixel has to be moved.
404
- * \param dy On return, this will be set to the amount the pixel has to be moved.
403
+ * \param dx On return, this will be changed by the amount the pixel has to be moved.
404
+ * \param dy On return, this will be changed by the amount the pixel has to be moved.
405 405
  */
406 406
 void xwindow_translate_for_gravity(xcb_gravity_t gravity, int16_t change_width_before, int16_t change_height_before,
407 407
         int16_t change_width_after, int16_t change_height_after, int16_t *dx, int16_t *dy)
@@ -449,9 +449,9 @@ void xwindow_translate_for_gravity(xcb_gravity_t gravity, int16_t change_width_b
449 449
     }
450 450
 
451 451
     if (dx)
452
-        *dx = x;
452
+        *dx += x;
453 453
     if (dy)
454
-        *dy = y;
454
+        *dy += y;
455 455
 }
456 456
 
457 457
 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80

Loading…
Cancel
Save