1- // Copyright (c) 2018-2019 Marco Wang <[email protected] >1+ // Copyright (c) 2018-2020 Marco Wang <[email protected] >22#include " client.h"
33
44#include " config.h"
@@ -50,16 +50,44 @@ void Client::Raise() const {
5050 XRaiseWindow (dpy_, window_);
5151}
5252
53- void Client::Move (int x, int y) const {
54- XMoveWindow (dpy_, window_, x, y);
53+ void Client::Move (int x, int y, bool absolute) const {
54+ if (absolute) {
55+ XMoveWindow (dpy_, window_, x, y);
56+ return ;
57+ }
58+
59+ XWindowAttributes attr = GetXWindowAttributes ();
60+ XMoveWindow (dpy_, window_, attr.x + x, attr.y + y);
5561}
5662
57- void Client::Resize (int w, int h) const {
63+ void Client::Resize (int w, int h, bool absolute) const {
64+ if (absolute) {
65+ ConstrainSize (w, h);
66+ XResizeWindow (dpy_, window_, w, h);
67+ return ;
68+ }
69+
70+ // Resize window by relative width and height.
71+ XWindowAttributes attr = GetXWindowAttributes ();
72+ w = attr.width + w;
73+ h = attr.height + h;
74+ ConstrainSize (w, h);
5875 XResizeWindow (dpy_, window_, w, h);
5976}
6077
61- void Client::MoveResize (int x, int y, int w, int h) const {
62- XMoveResizeWindow (dpy_, window_, x, y, w, h);
78+ void Client::MoveResize (int x, int y, int w, int h, bool absolute) const {
79+ if (absolute) {
80+ ConstrainSize (w, h);
81+ XMoveResizeWindow (dpy_, window_, x, y, w, h);
82+ return ;
83+ }
84+
85+ // Resize window by relative width and height.
86+ XWindowAttributes attr = GetXWindowAttributes ();
87+ w = attr.width + w;
88+ h = attr.height + h;
89+ ConstrainSize (w, h);
90+ XMoveResizeWindow (dpy_, window_, attr.x + x, attr.y + y, w, h);
6391}
6492
6593void Client::MoveResize (int x, int y, const std::pair<int , int >& size) const {
@@ -86,6 +114,56 @@ XWindowAttributes Client::GetXWindowAttributes() const {
86114 return wm_utils::GetXWindowAttributes (window_);
87115}
88116
117+ void Client::Move (const Action& action) const {
118+ const int & move_step = workspace_->config ()->float_move_step ();
119+ int x_offset = 0 ;
120+ int y_offset = 0 ;
121+
122+ switch (action.type ()) {
123+ case Action::Type::FLOAT_MOVE_LEFT:
124+ x_offset = -move_step;
125+ break ;
126+ case Action::Type::FLOAT_MOVE_RIGHT:
127+ x_offset = move_step;
128+ break ;
129+ case Action::Type::FLOAT_MOVE_UP:
130+ y_offset = -move_step;
131+ break ;
132+ case Action::Type::FLOAT_MOVE_DOWN:
133+ y_offset = move_step;
134+ break ;
135+ default :
136+ break ;
137+ }
138+
139+ Move (x_offset, y_offset, /* absolute=*/ false );
140+ }
141+
142+ void Client::Resize (const Action& action) const {
143+ const int & resize_step = workspace_->config ()->float_resize_step ();
144+ int width_offset = 0 ;
145+ int height_offset = 0 ;
146+
147+ switch (action.type ()) {
148+ case Action::Type::FLOAT_RESIZE_LEFT:
149+ width_offset = -resize_step;
150+ break ;
151+ case Action::Type::FLOAT_RESIZE_RIGHT:
152+ width_offset = resize_step;
153+ break ;
154+ case Action::Type::FLOAT_RESIZE_UP:
155+ height_offset = -resize_step;
156+ break ;
157+ case Action::Type::FLOAT_RESIZE_DOWN:
158+ height_offset = resize_step;
159+ break ;
160+ default :
161+ break ;
162+ }
163+
164+ Resize (width_offset, height_offset, /* absolute=*/ false );
165+ }
166+
89167Window Client::window () const {
90168 return window_;
91169}
@@ -142,6 +220,13 @@ void Client::set_attr_cache(const XWindowAttributes& attr) {
142220 attr_cache_ = attr;
143221}
144222
223+ void Client::ConstrainSize (int & w, int & h) const {
224+ const int min_w = (size_hints_.flags & PMinSize) ? size_hints_.min_width : MIN_WINDOW_WIDTH;
225+ const int min_h = (size_hints_.flags & PMinSize) ? size_hints_.min_height : MIN_WINDOW_HEIGHT;
226+ w = (w < min_w) ? min_w : w;
227+ h = (h < min_h) ? min_h : h;
228+ }
229+
145230Client::Area::Area () : x(), y(), w(), h() {}
146231
147232Client::Area::Area (int x, int y, int w, int h) : x(x), y(y), w(w), h(h) {}
0 commit comments