openbox-window-snap.diff 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. diff --git a/openbox/client.h b/openbox/client.h
  2. index 11a01400..a69c25ec 100644
  3. --- a/openbox/client.h
  4. +++ b/openbox/client.h
  5. @@ -268,6 +268,10 @@ struct _ObClient
  6. gboolean max_vert;
  7. /*! The window is maximized to fill the screen horizontally */
  8. gboolean max_horz;
  9. + /*! The window is snapped to fill the left side of the screen */
  10. + gboolean snapped_left;
  11. + /*! The window is snapped to fill the right side of the screen */
  12. + gboolean snapped_right;
  13. /*! The window should not be displayed by pagers */
  14. gboolean skip_pager;
  15. /*! The window should not be displayed by taskbars */
  16. diff --git a/openbox/moveresize.c b/openbox/moveresize.c
  17. index d12a64de..1a2c40b3 100644
  18. --- a/openbox/moveresize.c
  19. +++ b/openbox/moveresize.c
  20. @@ -372,7 +372,7 @@ void moveresize_end(gboolean cancel)
  21. static void do_move(gboolean keyboard, gint keydist)
  22. {
  23. - gint resist;
  24. + gint resist, x, y;
  25. if (keyboard) resist = keydist - 1; /* resist for one key press */
  26. else resist = config_resist_win;
  27. @@ -380,6 +380,69 @@ static void do_move(gboolean keyboard, gint keydist)
  28. if (!keyboard) resist = config_resist_edge;
  29. resist_move_monitors(moveresize_client, resist, &cur_x, &cur_y);
  30. + screen_pointer_pos(&x, &y);
  31. +
  32. + const Rect *a = screen_physical_area_active();
  33. + gint height = RECT_BOTTOM(*a) - RECT_TOP(*a);
  34. + gint width = RECT_RIGHT(*a) - RECT_LEFT(*a);
  35. +
  36. + if (moveresize_client->max_horz && moveresize_client->max_vert && y > 0)
  37. + {
  38. + client_maximize(moveresize_client, FALSE, 0);
  39. + start_cx = 0;
  40. + start_cy = 0;
  41. + start_x = ((x - cur_x) * moveresize_client->area.width) / cur_w;
  42. + start_y = y;
  43. + cur_x = x - start_x;
  44. + cur_y = y - start_y;
  45. + cur_w = moveresize_client->area.width;
  46. + cur_h = moveresize_client->area.height;
  47. + }
  48. + else if (y == 0 && !moveresize_client->snapped_left && !moveresize_client->snapped_right) {
  49. + client_maximize(moveresize_client, TRUE, 0);
  50. + }
  51. + else if (x == 0 && !moveresize_client->snapped_left && !moveresize_client->max_horz && !moveresize_client->max_vert) {
  52. + moveresize_client->pre_max_area.x = cur_x;
  53. + moveresize_client->pre_max_area.y = cur_y;
  54. + moveresize_client->pre_max_area.width = cur_w;
  55. + moveresize_client->pre_max_area.height = cur_h;
  56. + moveresize_client->snapped_left = TRUE;
  57. + }
  58. + else if (x > 0 && moveresize_client->snapped_left && !moveresize_client->max_horz && !moveresize_client->max_vert) {
  59. + cur_x = moveresize_client->pre_max_area.x;
  60. + cur_y = moveresize_client->pre_max_area.y;
  61. + cur_w = moveresize_client->pre_max_area.width;
  62. + cur_h = moveresize_client->pre_max_area.height;
  63. + moveresize_client->snapped_left = FALSE;
  64. + }
  65. + else if (x == width && !moveresize_client->snapped_right && !moveresize_client->max_horz && !moveresize_client->max_vert) {
  66. + moveresize_client->pre_max_area.x = cur_x;
  67. + moveresize_client->pre_max_area.y = cur_y;
  68. + moveresize_client->pre_max_area.width = cur_w;
  69. + moveresize_client->pre_max_area.height = cur_h;
  70. + moveresize_client->snapped_right = TRUE;
  71. + }
  72. + else if (x < width && moveresize_client->snapped_right && !moveresize_client->max_horz && !moveresize_client->max_vert) {
  73. + cur_x = moveresize_client->pre_max_area.x;
  74. + cur_y = moveresize_client->pre_max_area.y;
  75. + cur_w = moveresize_client->pre_max_area.width;
  76. + cur_h = moveresize_client->pre_max_area.height;
  77. + moveresize_client->snapped_right = FALSE;
  78. + }
  79. +
  80. + if (moveresize_client->snapped_left) {
  81. + cur_x = 0;
  82. + cur_y = 0;
  83. + cur_w = (width / 2) - 1;
  84. + cur_h = height;
  85. + }
  86. + else if (moveresize_client->snapped_right) {
  87. + cur_x = width / 2;
  88. + cur_y = 0;
  89. + cur_w = width / 2;
  90. + cur_h = height;
  91. + }
  92. +
  93. client_configure(moveresize_client, cur_x, cur_y, cur_w, cur_h,
  94. TRUE, FALSE, FALSE);
  95. if (config_resize_popup_show == 2) /* == "Always" */