]> Dogcows Code - chaz/openbox/blobdiff - util/epist/window.cc
add manpages for epist and for xftlsfonts
[chaz/openbox] / util / epist / window.cc
index 7ee674268551c8e3d8598bc66a2f717472967d1c..48df206c989b9c9dc18319fe4ae5e643e666e1bc 100644 (file)
@@ -1,5 +1,5 @@
 // -*- mode: C++; indent-tabs-mode: nil; -*-
-// window.cc for Epistophy - a key handler for NETWM/EWMH window managers.
+// window.cc for Epistrophy - a key handler for NETWM/EWMH window managers.
 // Copyright (c) 2002 - 2002 Ben Jansens <ben at orodu.net>
 //
 // Permission is hereby granted, free of charge, to any person obtaining a
@@ -44,8 +44,9 @@ XWindow::XWindow(epist *epist, screen *screen, Window window)
   XSelectInput(_epist->getXDisplay(), _window,
                PropertyChangeMask | StructureNotifyMask);
 
+  updateNormalHints();
+  updateWMHints();
   updateDimentions();
-  updateGravity();
   updateState();
   updateDesktop();
   updateTitle();
@@ -77,15 +78,40 @@ void XWindow::updateDimentions() {
 }
 
 
-void XWindow::updateGravity() {
+void XWindow::updateNormalHints() {
   XSizeHints size;
   long ret;
 
-  if (XGetWMNormalHints(_epist->getXDisplay(), _window, &size, &ret) &&
-      (size.flags & PWinGravity))
-    _gravity = size.win_gravity;
-  else
-    _gravity = NorthWestGravity;
+  // defaults
+  _gravity = NorthWestGravity;
+  _inc_x = _inc_y = 1;
+  _base_x = _base_y = 0;
+  
+  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;
+    }
+  }
+}
+
+
+void XWindow::updateWMHints() {
+  XWMHints *hints;
+
+  if ((hints = XGetWMHints(_epist->getXDisplay(), _window)) != NULL) {
+    _can_focus = hints->input;
+    XFree(hints);
+  } else {
+    // assume a window takes input if it doesnt specify
+    _can_focus = True;
+  }
 }
 
 
@@ -158,7 +184,9 @@ void XWindow::processEvent(const XEvent &e) {
     break;
   case PropertyNotify:
     if (e.xproperty.atom == XA_WM_NORMAL_HINTS)
-      updateGravity();
+      updateNormalHints();
+    if (e.xproperty.atom == XA_WM_HINTS)
+      updateWMHints();
     else if (e.xproperty.atom == _xatom->getAtom(XAtom::net_wm_state))
       updateState();
     else if (e.xproperty.atom == _xatom->getAtom(XAtom::net_wm_desktop))
@@ -207,9 +235,11 @@ void XWindow::iconify() const {
 
 
 void XWindow::focus() const {
-  // this will also unshade the window..
+  // this will cause the window to be uniconified also
   _xatom->sendClientMessage(_screen->rootWindow(), XAtom::net_active_window,
                             _window);
+  //XSetInputFocus(_epist->getXDisplay(), _window, None, CurrentTime);
 }
 
 
@@ -306,8 +336,39 @@ void XWindow::move(int x, int y) const {
 }
 
 
-void XWindow::resize(unsigned int width, unsigned int height) const {
-  XResizeWindow(_epist->getXDisplay(), _window, width, height);
+void XWindow::resizeRel(int dwidth, int dheight) const {
+  // resize in increments if requested by the window
+  unsigned int width = _rect.width(), height = _rect.height();
+  
+  unsigned int wdest = width + (dwidth * _inc_x) / _inc_x * _inc_x + _base_x;
+  unsigned int hdest = height + (dheight * _inc_y) / _inc_y * _inc_y + _base_y;
+
+  XResizeWindow(_epist->getXDisplay(), _window, wdest, hdest);
+}
+
+
+void XWindow::resizeAbs(unsigned int width, unsigned int height) const {
+  // 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);
 }
 
 
This page took 0.025839 seconds and 4 git commands to generate.