]> Dogcows Code - chaz/openbox/blobdiff - src/Window.cc
Take menu file from rc file if it isn't specified on the command line.
[chaz/openbox] / src / Window.cc
index c5d3db39e0da8c48e93ac2017dfbf50bdecad542..680943e214d5eb3c3e8453b8043f4573ad086064 100644 (file)
@@ -134,12 +134,11 @@ BlackboxWindow::BlackboxWindow(Blackbox *b, Window w, BScreen *s) {
 
   frame.ulabel_pixel = frame.flabel_pixel = frame.utitle_pixel =
   frame.ftitle_pixel = frame.uhandle_pixel = frame.fhandle_pixel =
-    frame.ubutton_pixel = frame.fbutton_pixel = frame.pbutton_pixel =
-    frame.uborder_pixel = frame.fborder_pixel = frame.ugrip_pixel =
-    frame.fgrip_pixel = 0;
+    frame.ubutton_pixel = frame.fbutton_pixel = frame.uborder_pixel =
+    frame.fborder_pixel = frame.ugrip_pixel = frame.fgrip_pixel = 0;
   frame.utitle = frame.ftitle = frame.uhandle = frame.fhandle = None;
   frame.ulabel = frame.flabel = frame.ubutton = frame.fbutton = None;
-  frame.pbutton = frame.ugrip = frame.fgrip = None;
+  frame.ugrip = frame.fgrip = None;
 
   functions = Func_Resize | Func_Move | Func_Iconify | Func_Maximize;
   mwm_decorations = Decor_Titlebar | Decor_Handle | Decor_Border |
@@ -571,11 +570,50 @@ void BlackboxWindow::decorate(void) {
   if (! frame.ubutton)
     frame.ubutton_pixel = texture->color().pixel();
 
-  texture = &(screen->getWindowStyle()->b_pressed);
-  frame.pbutton = texture->render(frame.button_w, frame.button_w,
-                                  frame.pbutton);
-  if (! frame.pbutton)
-    frame.pbutton_pixel = texture->color().pixel();
+  unsigned char needsPressed = 0;
+
+  texture = &(screen->getWindowStyle()->b_pressed_focus);
+  
+  if (texture->texture() != BTexture::NoTexture) {
+    frame.pfbutton = texture->render(frame.button_w, frame.button_w,
+                                     frame.pfbutton);
+    if (! frame.pfbutton)
+      frame.pfbutton_pixel = texture->color().pixel();
+  } else {
+    needsPressed = 0x1;
+  }
+
+  texture = &(screen->getWindowStyle()->b_pressed_unfocus);
+  
+  if (texture->texture() != BTexture::NoTexture) {
+    frame.pubutton = texture->render(frame.button_w, frame.button_w,
+                                     frame.pubutton);
+    if (! frame.pubutton)
+      frame.pubutton = texture->color().pixel();
+  } else {
+    needsPressed |= 0x2;
+  }
+
+  // if we either pressed unfocused, or pressed focused were undefined,
+  // make them inherit from the old resource. It's a hack for sure, but
+  // it allows for some backwards and forwards compatibility.
+  if (needsPressed) {
+    texture = &(screen->getWindowStyle()->b_pressed);
+    
+    if (needsPressed & 0x1) {
+      frame.pfbutton = texture->render(frame.button_w, frame.button_w,
+                                       frame.pfbutton);
+      if (! frame.pfbutton)
+        frame.pfbutton_pixel = texture->color().pixel();
+    }
+    if (needsPressed & 0x2) {
+      frame.pubutton = texture->render(frame.button_w, frame.button_w,
+                                       frame.pubutton);
+      if (! frame.pubutton)
+        frame.pubutton = texture->color().pixel();
+    }
+    
+  }
 
   if (decorations & Decor_Titlebar) {
     texture = &(screen->getWindowStyle()->t_focus);
@@ -747,9 +785,6 @@ void BlackboxWindow::destroyTitlebar(void) {
   if (frame.ubutton)
     screen->getImageControl()->removeImage(frame.ubutton);
 
-  if (frame.pbutton)
-    screen->getImageControl()->removeImage(frame.pbutton);
-
   blackbox->removeWindowSearch(frame.title);
   blackbox->removeWindowSearch(frame.label);
 
@@ -2589,35 +2624,50 @@ void BlackboxWindow::redrawAllButtons(void) const {
 }
 
 
-void BlackboxWindow::redrawIconifyButton(bool pressed) const {
-  if (! pressed) {
+void BlackboxWindow::redrawButton(bool pressed, Window win,
+                                  Pixmap fppix, unsigned long fppixel,
+                                  Pixmap uppix, unsigned long uppixel,
+                                  Pixmap fpix, unsigned long fpixel,
+                                  Pixmap upix, unsigned long upixel) const {
+  Pixmap p;
+  unsigned long pix;
+  
+  if (pressed) {
     if (flags.focused) {
-      if (frame.fbutton)
-        XSetWindowBackgroundPixmap(blackbox->getXDisplay(),
-                                   frame.iconify_button, frame.fbutton);
-      else
-        XSetWindowBackground(blackbox->getXDisplay(),
-                             frame.iconify_button, frame.fbutton_pixel);
+      p = fppix;
+      pix = fppixel;
     } else {
-      if (frame.ubutton)
-        XSetWindowBackgroundPixmap(blackbox->getXDisplay(),
-                                   frame.iconify_button, frame.ubutton);
-      else
-        XSetWindowBackground(blackbox->getXDisplay(), frame.iconify_button,
-                             frame.ubutton_pixel);
+      p = uppix;
+      pix = uppixel;
     }
   } else {
-    if (frame.pbutton)
-      XSetWindowBackgroundPixmap(blackbox->getXDisplay(),
-                                 frame.iconify_button, frame.pbutton);
-    else
-      XSetWindowBackground(blackbox->getXDisplay(),
-                           frame.iconify_button, frame.pbutton_pixel);
+    if (flags.focused) {
+      p = fpix;
+      pix = fpixel;
+    } else {
+      p = upix;
+      pix = upixel;
+    }
   }
+  
+  if (p)
+    XSetWindowBackgroundPixmap(blackbox->getXDisplay(), win, p);
+  else
+    XSetWindowBackground(blackbox->getXDisplay(), win, pix);
+
+}
+
+void BlackboxWindow::redrawIconifyButton(bool pressed) const {
+  redrawButton(pressed, frame.iconify_button, 
+               frame.pfbutton, frame.pfbutton_pixel,
+               frame.pubutton, frame.pubutton_pixel,
+               frame.fbutton, frame.fbutton_pixel,
+               frame.ubutton, frame.ubutton_pixel);
 
   XClearWindow(blackbox->getXDisplay(), frame.iconify_button);
   BPen pen((flags.focused) ? screen->getWindowStyle()->b_pic_focus :
              screen->getWindowStyle()->b_pic_unfocus);
+
 #ifdef    BITMAPBUTTONS
   PixmapMask pm = screen->getWindowStyle()->icon_button;
   
@@ -2643,30 +2693,12 @@ void BlackboxWindow::redrawIconifyButton(bool pressed) const {
 
 
 void BlackboxWindow::redrawMaximizeButton(bool pressed) const {
-  if (! pressed) {
-    if (flags.focused) {
-      if (frame.fbutton)
-        XSetWindowBackgroundPixmap(blackbox->getXDisplay(),
-                                   frame.maximize_button, frame.fbutton);
-      else
-        XSetWindowBackground(blackbox->getXDisplay(), frame.maximize_button,
-                             frame.fbutton_pixel);
-    } else {
-      if (frame.ubutton)
-        XSetWindowBackgroundPixmap(blackbox->getXDisplay(),
-                                   frame.maximize_button, frame.ubutton);
-      else
-        XSetWindowBackground(blackbox->getXDisplay(), frame.maximize_button,
-                             frame.ubutton_pixel);
-    }
-  } else {
-    if (frame.pbutton)
-      XSetWindowBackgroundPixmap(blackbox->getXDisplay(),
-                                 frame.maximize_button, frame.pbutton);
-    else
-      XSetWindowBackground(blackbox->getXDisplay(), frame.maximize_button,
-                           frame.pbutton_pixel);
-  }
+  redrawButton(pressed, frame.maximize_button, 
+               frame.pfbutton, frame.pfbutton_pixel,
+               frame.pubutton, frame.pubutton_pixel,
+               frame.fbutton, frame.fbutton_pixel,
+               frame.ubutton, frame.ubutton_pixel);
+
   XClearWindow(blackbox->getXDisplay(), frame.maximize_button);
 
   BPen pen((flags.focused) ? screen->getWindowStyle()->b_pic_focus :
@@ -2699,30 +2731,12 @@ void BlackboxWindow::redrawMaximizeButton(bool pressed) const {
 
 
 void BlackboxWindow::redrawCloseButton(bool pressed) const {
-  if (! pressed) {
-    if (flags.focused) {
-      if (frame.fbutton)
-        XSetWindowBackgroundPixmap(blackbox->getXDisplay(),
-                                   frame.close_button, frame.fbutton);
-      else
-        XSetWindowBackground(blackbox->getXDisplay(), frame.close_button,
-                             frame.fbutton_pixel);
-    } else {
-      if (frame.ubutton)
-        XSetWindowBackgroundPixmap(blackbox->getXDisplay(), frame.close_button,
-                                   frame.ubutton);
-      else
-        XSetWindowBackground(blackbox->getXDisplay(), frame.close_button,
-                             frame.ubutton_pixel);
-    }
-  } else {
-    if (frame.pbutton)
-      XSetWindowBackgroundPixmap(blackbox->getXDisplay(),
-                                 frame.close_button, frame.pbutton);
-    else
-      XSetWindowBackground(blackbox->getXDisplay(),
-                           frame.close_button, frame.pbutton_pixel);
-  }
+  redrawButton(pressed, frame.close_button, 
+               frame.pfbutton, frame.pfbutton_pixel,
+               frame.pubutton, frame.pubutton_pixel,
+               frame.fbutton, frame.fbutton_pixel,
+               frame.ubutton, frame.ubutton_pixel);
+
   XClearWindow(blackbox->getXDisplay(), frame.close_button);
 
   BPen pen((flags.focused) ? screen->getWindowStyle()->b_pic_focus :
@@ -2755,30 +2769,12 @@ void BlackboxWindow::redrawCloseButton(bool pressed) const {
 }
 
 void BlackboxWindow::redrawStickyButton(bool pressed) const {
-  if (! pressed) {
-    if (flags.focused) {
-      if (frame.fbutton)
-        XSetWindowBackgroundPixmap(blackbox->getXDisplay(),
-                                   frame.stick_button, frame.fbutton);
-      else
-        XSetWindowBackground(blackbox->getXDisplay(), frame.stick_button,
-                             frame.fbutton_pixel);
-    } else {
-      if (frame.ubutton)
-        XSetWindowBackgroundPixmap(blackbox->getXDisplay(),
-                                   frame.stick_button, frame.ubutton);
-      else
-        XSetWindowBackground(blackbox->getXDisplay(), frame.stick_button,
-                             frame.ubutton_pixel);
-    }
-  } else {
-    if (frame.pbutton)
-      XSetWindowBackgroundPixmap(blackbox->getXDisplay(),
-                                 frame.stick_button, frame.pbutton);
-    else
-      XSetWindowBackground(blackbox->getXDisplay(), frame.stick_button,
-                           frame.pbutton_pixel);
-  }
+  redrawButton(pressed, frame.stick_button, 
+               frame.pfbutton, frame.pfbutton_pixel,
+               frame.pubutton, frame.pubutton_pixel,
+               frame.fbutton, frame.fbutton_pixel,
+               frame.ubutton, frame.ubutton_pixel);
+
   XClearWindow(blackbox->getXDisplay(), frame.stick_button);
 
   BPen pen((flags.focused) ? screen->getWindowStyle()->b_pic_focus :
@@ -3179,6 +3175,10 @@ void BlackboxWindow::buttonPressEvent(const XButtonEvent *be) {
         my = top_edge;
       else if (my > bottom_edge)
         my = bottom_edge;
+      
+      if (my + windowmenu->getHeight() > screen->getHeight())
+        my = screen->getHeight() - windowmenu->getHeight() -
+          (screen->getBorderWidth() * 2);
 
       windowmenu->move(mx, my);
       windowmenu->show();
@@ -3364,7 +3364,7 @@ void BlackboxWindow::doWorkspaceWarping(int x_root, int y_root, int &dx) {
   bool focus = flags.focused; // had focus while moving?
 
   int dest_x = x_root;
-  if (x_root < 0) {
+  if (x_root <= 0) {
     dest_x += screen->getRect().width() - 1;
     dx += screen->getRect().width() - 1;
   } else {
@@ -4225,8 +4225,6 @@ void BlackboxWindow::constrain(Corner anchor,
     if (dh > client.max_height) dh = client.max_height;
   }
 
-  assert(dw >= base_width && dh >= base_height);
-
   if (client.width_inc > 1) {
     dw -= base_width;
     dw /= client.width_inc;
This page took 0.03242 seconds and 4 git commands to generate.