[Y-devel] minimize patch (sortof) and what is needed to get it right

Thomas spiralman at softhome.net
Fri Feb 20 17:02:44 GMT 2004


Hello.  I was reading through code and decided to write a patch to support 
minimizing windows.  This was partially just my way of getting used to the 
source code (although i still have a long way to go), but it is also a 
feature that needs to be implemented eventually.

Currently this does not actually hide windows, but instead "shades" them 
(makes them only display their title bars), but all the hooks to do actual 
minimizing are in there.  In this case even that doesnt happen perfectly, 
because the widgetResize() function keeps the minimum height to large for the 
display to look quite right.  

I have also changed some code that assumed that the only valid values of 
WindowSizeState were WINDOW_SIZE_NORMAL and WINDOW_SIZE_MAXIMISE 
(ie, they check for WINDOW_SIZE_NORMAL and if it isnt, they assume it is 
maximized).  I also added a WINDOW_SIZE_MINIMIZE value to the enum.

There were two reasons i did not actually implement minimizing: first, the 
desktop has no way of hiding/showing windows, it can only remove them.  based 
on the current code, it looks like there are two easy ways to implement this, 
either with a flag in the window class to set whether it is hidden or not, or 
by implementing a separate list of "hidden windows" in the desktop class and 
have show/hide move the windows between the lists (i prefer this second way 
myself).  This would certainly make showing/hiding windows slower, but 
drawing windows would operate faster, which is, imho, the better place to put 
the speedup.

The second reason i did not implement actual window minimizing is that there 
is currently no GUI available to unminimize the window.  presumably this 
would be done in some sort of taskbar (a. la. windows), a desktop mouse menu 
(*box) or even desktop icons (twm, etc).  This got me to thinking about how 
and where a person would implement this feature.  In the X environment this 
would be done in the window manager, but since the window manager is just 
another module in Y, perhaps it would be better to make a "task manager" 
module, which the user could swap in and out, and, presumably, a window 
manager module could also implement a task manager module and provide both 
functionalities. 

anyway, here, finally, is the patch

Thomas Stephens
spiralman at softhome.net

--- orig/Y/modules/windowmanager_interface.h
+++ mod/Y/modules/windowmanager_interface.h
@@ -28,6 +28,7 @@
   void (*selectWindow) (struct WindowManager *, struct Window *);
   void (*maximiseWindow) (struct WindowManager *, struct Window *);
   void (*restoreWindow) (struct WindowManager *, struct Window *);
+  void (*minimizeWindow) (struct WindowManager *, struct Window *);
 };
 
 #endif
--- orig/Y/modules/windowmanager.h
+++ mod/Y/modules/windowmanager.h
@@ -24,6 +24,7 @@
 void           wmSelectWindow (struct Window *);
 void           wmMaximiseWindow (struct Window *);
 void           wmRestoreWindow (struct Window *);
+void           wmMinimizeWindow (struct Window *);
 
 #endif /* macro guard */
 
--- orig/Y/modules/windowmanager.c
+++ mod/Y/modules/windowmanager.c
@@ -109,5 +109,13 @@
   return currentWindowManager -> restoreWindow (currentWindowManager, w);
 }
 
+void
+wmMinimizeWindow (struct Window *w)
+{
+  if (currentWindowManager == NULL)
+    return;
+  return currentWindowManager -> minimizeWindow (currentWindowManager, w);
+}
+
 /* arch-tag: 07b8bf39-884b-49a3-a3e6-1769c44432a2
  */
--- orig/Y/widget/window.h
+++ mod/Y/widget/window.h
@@ -14,7 +14,7 @@
 
 enum WindowSizeState
 {
-  WINDOW_SIZE_NORMAL, WINDOW_SIZE_MAXIMISE
+  WINDOW_SIZE_NORMAL, WINDOW_SIZE_MAXIMISE, WINDOW_SIZE_MINIMIZE
 };
 
 #include <Y/y.h>
--- orig/Y/widget/desktop.c
+++ mod/Y/widget/desktop.c
@@ -257,6 +257,7 @@
       switch (winState)
         {
           case WINDOW_SIZE_NORMAL:
+          case WINDOW_SIZE_MINIMIZE:
             /* push any off bottom/right windows back on-to the screen,
              * if possible */
             if (newRect -> w > self -> widget.w)
@@ -275,7 +276,6 @@
           case WINDOW_SIZE_MAXIMISE:
             /* just resize it */
             widgetResize (windowToWidget (win), self -> widget.w, self -> 
widget.h);
-            break;
         }
       rectangleDestroy (winRect);
       rectangleDestroy (newRect);
--- orig/modules/themes/basic/window.c
+++ mod/modules/themes/basic/window.c
@@ -29,7 +29,7 @@
 enum WindowRegion
 {
 WINDOW_REGION_NOTHING,
-WINDOW_REGION_MOVE,
+WINDOW_REGION_MOVE, WINDOW_REGION_MINIMIZE,
 WINDOW_REGION_MAXIMISE, WINDOW_REGION_RESTORE, WINDOW_REGION_CLOSE,
 WINDOW_REGION_RESIZE_NW, WINDOW_REGION_RESIZE_N, WINDOW_REGION_RESIZE_NE,
 WINDOW_REGION_RESIZE_W,                          WINDOW_REGION_RESIZE_E,
@@ -80,16 +80,18 @@
   painterSetPenColour (painter, 0xFFFFFFFF);
   painterDrawLine (painter, x + w - 12, y + 5,  7,  7);
   painterDrawLine (painter, x + w -  6, y + 5, -7,  7);
-  if (windowGetSizeState (window) == WINDOW_SIZE_NORMAL)
+  if (windowGetSizeState (window) == WINDOW_SIZE_MAXIMISE)
     {
-      painterDrawLine (painter, x + w - 22, y + 5, -4,  7);
-      painterDrawLine (painter, x + w - 22, y + 5,  4,  7);
+      painterDrawLine (painter, x + w - 22, y + 12, -4, -7);
+      painterDrawLine (painter, x + w - 22, y + 12,  4, -7);
     }
   else
     {
-      painterDrawLine (painter, x + w - 22, y + 12, -4, -7);
-      painterDrawLine (painter, x + w - 22, y + 12,  4, -7);
+      painterDrawLine (painter, x + w - 22, y + 5, -4,  7);
+      painterDrawLine (painter, x + w - 22, y + 5,  4,  7);
     }
+  /*Minimize button*/
+  painterDrawHLine( painter, x + w - 39, y + 12, 7 );
 
 }
 
@@ -104,7 +106,7 @@
            ? objectGetPropertyAsInteger (windowToObject (window), 
"background")
            : bgcolour;
 
-  if (windowGetSizeState (window) == WINDOW_SIZE_NORMAL)
+  if (windowGetSizeState (window) != WINDOW_SIZE_MAXIMISE)
     {
       /* resizing border */
       painterSetBlendMode   (painter, COLOUR_BLEND_SOURCE);
@@ -135,7 +137,7 @@
   rectangleDestroy (rect);
 
   /* paint child */
-  if (child != NULL)
+  if (child != NULL && windowGetSizeState (window) != WINDOW_SIZE_MINIMIZE)
     {
       struct Rectangle *childRect = widgetGetRectangle (child);
       painterSaveState (painter);
@@ -168,6 +170,11 @@
         wy = 0;
         ww = rect -> w;
         wh = rect -> h;
+      case WINDOW_SIZE_MINIMIZE:
+        wx = 5;
+        wy = 5;
+        ww = rect -> w - 10;
+        wh = rect -> h - 10;
     }
 
   if (y > wy && y <= wy + 19)
@@ -176,13 +183,20 @@
         region = WINDOW_REGION_MOVE;
       if (x >= wx + ww - 27 && x < wx + ww - 14)
         {
-          if (windowGetSizeState (window) == WINDOW_SIZE_NORMAL)
-            region = WINDOW_REGION_MAXIMISE;
-          else
+          if (windowGetSizeState (window) == WINDOW_SIZE_MAXIMISE)
             region = WINDOW_REGION_RESTORE;
+          else
+            region = WINDOW_REGION_MAXIMISE;
         }
       if (x >= wx + ww - 14 && x <= wx + ww)
         region = WINDOW_REGION_CLOSE;
+      if (x >= wx + ww - 41 && x <= wx + ww - 28)
+        {
+          if (windowGetSizeState (window) == WINDOW_SIZE_MINIMIZE)
+            region = WINDOW_REGION_RESTORE;
+          else
+            region = WINDOW_REGION_MINIMIZE;
+        }
     }
   if (x > wx && x < wx + ww && y > wy + 19 && y < wy + wh)
     region = WINDOW_REGION_CHILD;
@@ -254,6 +268,8 @@
             windowStartReshape (w, x, y, WINDOW_RESHAPE_MOVE); break;
           case WINDOW_REGION_MAXIMISE:
             wmMaximiseWindow (w);   break;
+         case WINDOW_REGION_MINIMIZE:
+           wmMinimizeWindow (w); break;
           case WINDOW_REGION_RESTORE:
             wmRestoreWindow (w);   break;
           case WINDOW_REGION_CLOSE:
@@ -373,6 +389,11 @@
           case WINDOW_SIZE_MAXIMISE:
             widgetMove (child, 0, 19);
             widgetResize (child, w, h - 19);
+            break;
+          case WINDOW_SIZE_MINIMIZE:
+            widgetMove (child, 5, 24);
+            widgetResize (child, w - 10, h - 29);
+            break;
         }  
     }
 }
--- orig/modules/wm/default/default.c
+++ mod/modules/wm/default/default.c
@@ -127,6 +127,20 @@
   windowRestoreGeometry (win);
 }
 
+static void
+defaultMinimizeWindow (struct WindowManager *wm, struct Window *win)
+{
+  int x, y, w, h;
+  defaultSelectWindow (wm, win);
+  widgetGetPosition (windowToWidget (win), &x, &y);
+  widgetGetSize (windowToWidget (win), &w, &h);
+  printf( "%dx%d %dx%d\n", x, y, w, h );
+  windowSaveGeometry (win);
+  windowSetSizeState (win, WINDOW_SIZE_MINIMIZE);
+  widgetMove (windowToWidget (win), x, y);
+  widgetResize (windowToWidget (win), w, 0);
+}
+
 int
 initialise (struct Module *m, int argc, const char **argv)
 {
@@ -144,6 +158,7 @@
   self -> selectWindow        = defaultSelectWindow;
   self -> maximiseWindow      = defaultMaximiseWindow;
   self -> restoreWindow       = defaultRestoreWindow;
+  self -> minimizeWindow      = defaultMinimizeWindow;
   self -> module = m;
   m -> name = "Default Window Manager";
   m -> data = self;



More information about the Y-devel mailing list









2026 © www.Y-Windows.Org - All Rights Reserved