implement window resizing. using resizing incrememnts if the window has requested them!

This commit is contained in:
Dana Jansens 2002-07-20 20:25:56 +00:00
parent 5b91573e0c
commit 675d16c71a
3 changed files with 46 additions and 12 deletions

View file

@ -46,8 +46,8 @@ public:
moveWindowDown, //done moveWindowDown, //done
moveWindowLeft, //done moveWindowLeft, //done
moveWindowRight, //done moveWindowRight, //done
resizeWindowWidth, resizeWindowWidth, //done
resizeWindowHeight, resizeWindowHeight, //done
toggleMaximizeFull, //done toggleMaximizeFull, //done
toggleMaximizeVertical, //done toggleMaximizeVertical, //done

View file

@ -44,8 +44,8 @@ XWindow::XWindow(epist *epist, screen *screen, Window window)
XSelectInput(_epist->getXDisplay(), _window, XSelectInput(_epist->getXDisplay(), _window,
PropertyChangeMask | StructureNotifyMask); PropertyChangeMask | StructureNotifyMask);
updateHints();
updateDimentions(); updateDimentions();
updateGravity();
updateState(); updateState();
updateDesktop(); updateDesktop();
updateTitle(); updateTitle();
@ -77,15 +77,27 @@ void XWindow::updateDimentions() {
} }
void XWindow::updateGravity() { void XWindow::updateHints() {
XSizeHints size; XSizeHints size;
long ret; long ret;
if (XGetWMNormalHints(_epist->getXDisplay(), _window, &size, &ret) && // defaults
(size.flags & PWinGravity)) _gravity = NorthWestGravity;
_gravity = size.win_gravity; _inc_x = _inc_y = 1;
else _base_x = _base_y = 0;
_gravity = NorthWestGravity;
if (XGetWMNormalHints(_epist->getXDisplay(), _window, &size, &ret)) {
if (size.flags & PWinGravity)
_gravity = size.win_gravity;
if (size.flags & PBaseSize) {
_base_x = size.base_width;
_base_y = size.base_height;
}
if (size.flags & PResizeInc) {
_inc_x = size.width_inc;
_inc_y = size.height_inc;
}
}
} }
@ -158,7 +170,7 @@ void XWindow::processEvent(const XEvent &e) {
break; break;
case PropertyNotify: case PropertyNotify:
if (e.xproperty.atom == XA_WM_NORMAL_HINTS) if (e.xproperty.atom == XA_WM_NORMAL_HINTS)
updateGravity(); updateHints();
else if (e.xproperty.atom == _xatom->getAtom(XAtom::net_wm_state)) else if (e.xproperty.atom == _xatom->getAtom(XAtom::net_wm_state))
updateState(); updateState();
else if (e.xproperty.atom == _xatom->getAtom(XAtom::net_wm_desktop)) else if (e.xproperty.atom == _xatom->getAtom(XAtom::net_wm_desktop))
@ -307,7 +319,27 @@ void XWindow::move(int x, int y) const {
void XWindow::resize(unsigned int width, unsigned int height) const { void XWindow::resize(unsigned int width, unsigned int height) const {
XResizeWindow(_epist->getXDisplay(), _window, width, height); // resize in increments if requested by the window
unsigned int wdest = width / _inc_x * _inc_x + _base_x;
unsigned int hdest = height / _inc_y * _inc_y + _base_y;
if (width > wdest) {
while (width > wdest)
wdest += _inc_x;
} else {
while (width < wdest)
wdest -= _inc_x;
}
if (height > hdest) {
while (height > hdest)
hdest += _inc_y;
} else {
while (height < hdest)
hdest -= _inc_y;
}
XResizeWindow(_epist->getXDisplay(), _window, wdest, hdest);
} }

View file

@ -57,6 +57,8 @@ private:
std::string _app_name; std::string _app_name;
std::string _app_class; std::string _app_class;
Rect _rect; Rect _rect;
int _inc_x, _inc_y; // resize increments
int _base_x, _base_y; // base size
int _gravity; int _gravity;
// states // states
@ -68,7 +70,7 @@ private:
bool _unmapped; bool _unmapped;
void updateDimentions(); void updateDimentions();
void updateGravity(); void updateHints();
void updateState(); void updateState();
void updateDesktop(); void updateDesktop();
void updateTitle(); void updateTitle();