changeset 40:6f3211a1f826

Icons.c: clang-format
author ng0@n0.is
date Fri, 03 May 2019 19:31:55 +0000
parents 0f2ba00462dd
children 1b09f89c5585
files Icons.c
diffstat 1 files changed, 296 insertions(+), 222 deletions(-) [+]
line wrap: on
line diff
--- a/Icons.c	Fri May 03 19:23:21 2019 +0000
+++ b/Icons.c	Fri May 03 19:31:55 2019 +0000
@@ -43,31 +43,31 @@
  */
 
 
- 
 /*
  * MODIFICATION HISTORY
  *
  * 000 -- L. Guarino Reid, DEC Ultrix Engineering Group
  */
- 
+
 #ifndef lint
 static char *sccsid = "%W%	%G%";
 #endif
- 
+
 #include "uwm.h"
 #include <X11/Xatom.h>
 #ifdef SHAPE
 #include <X11/extensions/shape.h>
 #endif
 
-typedef struct _windowList {
-  struct _windowList *next;
-  Window window;
-  Window icon;
-  bool own;
-  Pixmap pixmap;
+typedef struct _windowList
+{
+        struct _windowList *next;
+        Window window;
+        Window icon;
+        bool own;
+        Pixmap pixmap;
 } WindowListRec, *WindowList;
-  
+
 WindowList Icons = NULL;
 
 
@@ -77,265 +77,339 @@
  * appropriate background and foreground pixels.
  *
  * we'll use the (global) IconGC for the fore/background pixels.
+ *
+ * Pixmap bitmap
+ * unsigned int *width_return
+ * unsigned int *height_return
  */
 
-static Pixmap MakePixmapFromBitmap( bitmap, width_return, height_return )
-Pixmap bitmap;
-unsigned int *width_return, *height_return;
+static Pixmap
+MakePixmapFromBitmap (Pixmap bitmap,
+                      unsigned int *width_return,
+                      unsigned int *height_return)
 {
-    Pixmap tile;
-    Window junkW;
-    int junk, width, height;
-
-    if (!XGetGeometry( dpy, bitmap, &junkW, &junk, &junk,
-		      &width, &height, &junk, &junk )) {
-        Warning( "client passed invalid pixmap for icon." );
-	return ( NULL );
-    }
+        Pixmap tile;
+        Window junkW;
+        int junk, width, height;
 
-    tile = XCreatePixmap( dpy, RootWindow(dpy, scr), width, height,
-			  DefaultDepth(dpy, scr) );
+        if (! XGetGeometry (dpy,
+                            bitmap,
+                            &junkW,
+                            &junk,
+                            &junk,
+                            &width,
+                            &height,
+                            &junk,
+                            &junk))
+        {
+                Warning ("client passed invalid pixmap for icon.");
+                return (NULL);
+        }
 
-    /* use the IconGC's foreground & background, so we don't have to
-     * create another (and add yet another user configuration option.
-     * someday this may need to be split out.
-     */
-    XCopyPlane( dpy, bitmap, tile, IconGC, 0, 0, width, height, 0, 0, 1 );
+        tile = XCreatePixmap (dpy,
+                              RootWindow (dpy, scr),
+                              width,
+                              height,
+                              DefaultDepth (dpy, scr));
 
-    if (width_return)  *width_return = width;
-    if (height_return) *height_return = height;
+        /* use the IconGC's foreground & background, so we don't have to
+         * create another (and add yet another user configuration option.
+         * someday this may need to be split out.
+         */
+        XCopyPlane (dpy, bitmap, tile, IconGC, 0, 0, width, height, 0, 0, 1);
 
-    return( tile );
+        if (width_return)
+                *width_return = width;
+        if (height_return)
+                *height_return = height;
+
+        return (tile);
 }
 
 
 char *
-GetIconName(window)
-Window window;
+GetIconName (Window window)
 {
-    char *name;
+        char *name;
 
-    if (XGetIconName( dpy, window, &name )) return( name );
+        if (XGetIconName (dpy, window, &name))
+                return (name);
 
-    if (XFetchName( dpy, window, &name )) return( name );
+        if (XFetchName (dpy, window, &name))
+                return (name);
 
-    return( NULL );
+        return (NULL);
 }
 
-bool IsIcon(icon, x, y, mousePositioned, assoc)
-Window icon;
-Window *assoc;
+bool
+IsIcon (Window icon, x, y, mousePositioned, Window *assoc)
 {
-  WindowList ptr;
-  Window MakeIcon();
+        WindowList ptr;
+        Window MakeIcon ();
 
-  for (ptr = Icons; ptr; ptr = ptr->next) {
-    if (ptr->icon == icon) {
-      if (assoc) *assoc = ptr->window; 
-      return(TRUE);
-    }
-    if (ptr->window == icon) {
-      if (assoc) *assoc = ptr->icon; 
-      return(FALSE);
-    }
-  }
-  if (assoc) *assoc = MakeIcon(icon, x, y, mousePositioned);
-  return(FALSE);
+        for (ptr = Icons; ptr; ptr = ptr->next)
+        {
+                if (ptr->icon == icon)
+                {
+                        if (assoc)
+                                *assoc = ptr->window;
+                        return (TRUE);
+                }
+                if (ptr->window == icon)
+                {
+                        if (assoc)
+                                *assoc = ptr->icon;
+                        return (FALSE);
+                }
+        }
+        if (assoc)
+                *assoc = MakeIcon (icon, x, y, mousePositioned);
+        return (FALSE);
 }
 
 
-RemoveIcon(window)
-Window window;
+RemoveIcon (Window window)
 {
-  WindowList ptr, ptr1;
+        WindowList ptr, ptr1;
 
-  for (ptr = Icons; ptr; ptr = ptr->next) 
-    if (ptr->window == window) {
-      if (ptr->own) {
-	  XDestroyWindow(dpy, ptr->icon);
-	  if (ptr->pixmap != IBackground) XFreePixmap(dpy, ptr->pixmap);
-      }
-      break;
-    }
-  if (ptr) {
-    if (ptr==Icons) Icons = Icons->next;
-    else 
-      for (ptr1 = Icons; ptr1->next; ptr1 = ptr1->next) 
-        if (ptr1->next == ptr) {
-          ptr1->next = ptr->next;
-	  break;
-        };
-    free(ptr);
-    }
+        for (ptr = Icons; ptr; ptr = ptr->next)
+                if (ptr->window == window)
+                {
+                        if (ptr->own)
+                        {
+                                XDestroyWindow (dpy, ptr->icon);
+                                if (ptr->pixmap != IBackground)
+                                        XFreePixmap (dpy, ptr->pixmap);
+                        }
+                        break;
+                }
+        if (ptr)
+        {
+                if (ptr == Icons)
+                        Icons = Icons->next;
+                else
+                        for (ptr1 = Icons; ptr1->next; ptr1 = ptr1->next)
+                                if (ptr1->next == ptr)
+                                {
+                                        ptr1->next = ptr->next;
+                                        break;
+                                };
+                free (ptr);
+        }
 }
 
-GetDefaultSize(window, icon_w, icon_h)
-Window window;
-int *icon_w, *icon_h;
+GetDefaultSize (Window window, int *icon_w, int *icon_h)
 {
-    char *name;				/* Event window name. */
+        char *name; /* Event window name. */
 
-          /*
-           * Determine the size of the icon window.
-           */ 
-          name = GetIconName(window);
-          *icon_h = IFontInfo->ascent + IFontInfo->descent;
-          if (name) {
-	    *icon_w = XTextWidth(IFontInfo, name, strlen(name));
-            if (*icon_w == 0)
-              *icon_w = *icon_h;
-	  } else 
-	    *icon_w = *icon_h;
-     }
-
-Window MakeIcon(window, x, y, mousePositioned)
-Window window;                          /* associated window. */
-int x, y;                               /* Event mouse position. */
-bool mousePositioned;
+        /*
+         * Determine the size of the icon window.
+         */
+        name = GetIconName (window);
+        *icon_h = IFontInfo->ascent + IFontInfo->descent;
+        if (name)
+        {
+                *icon_w = XTextWidth (IFontInfo, name, strlen (name));
+                if (*icon_w == 0)
+                        *icon_w = *icon_h;
+        }
+        else
+                *icon_w = *icon_h;
+}
+/*
+ * Window window: associated window.
+ * int x, y: Event mouse position.
+ * bool mousePositioned
+ */
+Window
+MakeIcon (Window window, int x, int y, bool mousePositioned)
 {
-    Window icon;			/* icon window. */
-    int icon_x, icon_y;			/* Icon U. L. X and Y coordinates. */
-    int icon_w, icon_h;			/* Icon width and height. */
-    int icon_bdr;			/* Icon border width. */
-    int mask;				/* Icon event mask */
-    int depth;				/* for XGetGeometry */
-    int dummy_event, dummy_error;       /* See XShapeQueryExtension() call. */
-    XSetWindowAttributes iconValues;	/* for icon window creation */
-    XWMHints *wmhints;			/* see if icon position provided */
-    XWMHints *XGetWMHints();
-    Window AddIcon();
- 
-   iconValues.background_pixmap = IBackground;
-   mask = (KeyPressMask|ExposureMask|StructureNotifyMask);
-   /*
-    * Process window manager hints.
-    */ 
-    if (wmhints = XGetWMHints(dpy, window)) {
-      if (wmhints->flags&IconWindowHint) {
-	  Window iw = wmhints->icon_window;
-	  free ((char *) wmhints);
-          return (AddIcon(window, iw, FALSE, 
-	  	  (StructureNotifyMask), (Pixmap)NULL));
-      } else if (wmhints->flags&IconPixmapHint) { 
-          iconValues.background_pixmap =
-	      MakePixmapFromBitmap( wmhints->icon_pixmap, &icon_w, &icon_h );
-	  if (iconValues.background_pixmap)
-	      mask = (StructureNotifyMask);
-	  else {
-	      iconValues.background_pixmap = IBackground;
-	      wmhints->flags &= ~IconPixmapHint;
-	      GetDefaultSize(window, &icon_w, &icon_h);
-	  }
-      }
-      else GetDefaultSize(window, &icon_w, &icon_h);
-    }
-    else GetDefaultSize(window, &icon_w, &icon_h);
+        Window icon; /* icon window. */
+        int icon_x, icon_y; /* Icon U. L. X and Y coordinates. */
+        int icon_w, icon_h; /* Icon width and height. */
+        int icon_bdr; /* Icon border width. */
+        int mask; /* Icon event mask */
+        int depth; /* for XGetGeometry */
+        int dummy_event, dummy_error; /* See XShapeQueryExtension() call. */
+        XSetWindowAttributes iconValues; /* for icon window creation */
+        XWMHints *wmhints; /* see if icon position provided */
+        XWMHints *XGetWMHints ();
+        Window AddIcon ();
 
-     /*
-      * Fix up sizes by padding.
-      */ 
-    if (!wmhints || !(wmhints->flags&(IconPixmapHint|IconWindowHint))) {
-      icon_w += (HIconPad << 1);
-      icon_h += (VIconPad << 1);
-    }
+        iconValues.background_pixmap = IBackground;
+        mask = (KeyPressMask | ExposureMask | StructureNotifyMask);
+        /*
+         * Process window manager hints.
+         */
+        if (wmhints = XGetWMHints (dpy, window))
+        {
+                if (wmhints->flags & IconWindowHint)
+                {
+                        Window iw = wmhints->icon_window;
+                        free ((char *) wmhints);
+                        return (AddIcon (window,
+                                         iw,
+                                         FALSE,
+                                         (StructureNotifyMask),
+                                         (Pixmap) NULL));
+                }
+                else if (wmhints->flags & IconPixmapHint)
+                {
+                        iconValues.background_pixmap =
+                          MakePixmapFromBitmap (wmhints->icon_pixmap,
+                                                &icon_w,
+                                                &icon_h);
+                        if (iconValues.background_pixmap)
+                                mask = (StructureNotifyMask);
+                        else
+                        {
+                                iconValues.background_pixmap = IBackground;
+                                wmhints->flags &= ~IconPixmapHint;
+                                GetDefaultSize (window, &icon_w, &icon_h);
+                        }
+                }
+                else
+                        GetDefaultSize (window, &icon_w, &icon_h);
+        }
+        else
+                GetDefaultSize (window, &icon_w, &icon_h);
+
+        /*
+         * Fix up sizes by padding.
+         */
+        if (! wmhints || ! (wmhints->flags & (IconPixmapHint | IconWindowHint)))
+        {
+                icon_w += (HIconPad << 1);
+                icon_h += (VIconPad << 1);
+        }
 
-     /*
-      * Set the icon border attributes.
-      */ 
-    if (!wmhints || !(wmhints->flags&IconWindowHint)) {
-      icon_bdr = IBorderWidth;
-      iconValues.border_pixel = IBorder;
-    }
- 
-    if (wmhints && (wmhints->flags&IconPositionHint)) {
-         icon_x = wmhints->icon_x;
-	 icon_y = wmhints->icon_y;
-    } else {
-      if (mousePositioned) {
         /*
-         * Determine the coordinates of the icon window;
-         * normalize so that we don't lose the icon off the
-         * edge of the screen.
+         * Set the icon border attributes.
          */
-        icon_x = x - (icon_w >> 1) + 1;
-        if (icon_x < 0) icon_x = 0;
-        icon_y = y - (icon_h >> 1) + 1;
-        if (icon_y < 0) icon_y = 0;
-        if ((icon_x - 1 + icon_w + (icon_bdr << 1)) > ScreenWidth) {
-           icon_x = ScreenWidth - icon_w - (icon_bdr << 1) + 1;
+        if (! wmhints || ! (wmhints->flags & IconWindowHint))
+        {
+                icon_bdr = IBorderWidth;
+                iconValues.border_pixel = IBorder;
         }
-        if ((icon_y - 1 + icon_h + (icon_bdr << 1)) > ScreenHeight) {
-           icon_y = ScreenHeight - icon_h - (icon_bdr << 1) + 1;
+
+        if (wmhints && (wmhints->flags & IconPositionHint))
+        {
+                icon_x = wmhints->icon_x;
+                icon_y = wmhints->icon_y;
         }
-      }
-      else {
-        icon_x = x + (icon_w >> 1);
-        icon_y = y + (icon_h >> 1);
-      }
-        
-    }
+        else
+        {
+                if (mousePositioned)
+                {
+                        /*
+                         * Determine the coordinates of the icon window;
+                         * normalize so that we don't lose the icon off the
+                         * edge of the screen.
+                         */
+                        icon_x = x - (icon_w >> 1) + 1;
+                        if (icon_x < 0)
+                                icon_x = 0;
+                        icon_y = y - (icon_h >> 1) + 1;
+                        if (icon_y < 0)
+                                icon_y = 0;
+                        if ((icon_x - 1 + icon_w + (icon_bdr << 1)) >
+                            ScreenWidth)
+                        {
+                                icon_x =
+                                  ScreenWidth - icon_w - (icon_bdr << 1) + 1;
+                        }
+                        if ((icon_y - 1 + icon_h + (icon_bdr << 1)) >
+                            ScreenHeight)
+                        {
+                                icon_y =
+                                  ScreenHeight - icon_h - (icon_bdr << 1) + 1;
+                        }
+                }
+                else
+                {
+                        icon_x = x + (icon_w >> 1);
+                        icon_y = y + (icon_h >> 1);
+                }
+        }
 
-   /*
-    * Create the icon window.
-    */
-   icon = XCreateWindow(
-                dpy, RootWindow(dpy, scr),
-                icon_x, icon_y,
-                icon_w, icon_h,
-                icon_bdr, 0, CopyFromParent, CopyFromParent,
-		CWBorderPixel+CWBackPixmap, &iconValues);
+        /*
+         * Create the icon window.
+         */
+        icon = XCreateWindow (dpy,
+                              RootWindow (dpy, scr),
+                              icon_x,
+                              icon_y,
+                              icon_w,
+                              icon_h,
+                              icon_bdr,
+                              0,
+                              CopyFromParent,
+                              CopyFromParent,
+                              CWBorderPixel + CWBackPixmap,
+                              &iconValues);
 
 #ifdef SHAPE
-   if (iconValues.background_pixmap != IBackground
-       && (wmhints->flags & IconMaskHint)
+        if (iconValues.background_pixmap != IBackground &&
+            (wmhints->flags & IconMaskHint)
 #if 0
        && XShapeQueryExtension(dpy)
-#else           
-       && XShapeQueryExtension(dpy, &dummy_event, &dummy_error)
+#else
+            && XShapeQueryExtension (dpy, &dummy_event, &dummy_error)
 #endif
-           ){
-           XSetWindowBorderWidth(dpy, icon, 0);
-           XShapeCombineMask(dpy, icon, ShapeBounding, 0, 0, wmhints->icon_mask,
-                             ShapeSet);
-   }
+        )
+        {
+                XSetWindowBorderWidth (dpy, icon, 0);
+                XShapeCombineMask (dpy,
+                                   icon,
+                                   ShapeBounding,
+                                   0,
+                                   0,
+                                   wmhints->icon_mask,
+                                   ShapeSet);
+        }
 #endif
 
-   if (wmhints) free ((char *) wmhints);
+        if (wmhints)
+                free ((char *) wmhints);
 
-   return(AddIcon(window, icon, TRUE, mask, iconValues.background_pixmap));
- 
+        return (
+          AddIcon (window, icon, TRUE, mask, iconValues.background_pixmap));
 }
 
-Window AddIcon(window, icon, own, mask, background)
-Window window, icon;
-bool own;
-int mask;
-Pixmap background;
+/*
+ * Window window, icon
+ * bool own
+ * int mask
+ * Pixmap background
+ */
+Window
+AddIcon (Window window, Window icon, bool own, int mask, Pixmap background)
 {
-  WindowList ptr;
+        WindowList ptr;
+
+        if (icon == NULL)
+                return (NULL);
+        /*
+         * Use the text cursor whenever the mouse is in the icon window.
+         */
+        XDefineCursor (dpy, icon, TextCursor);
 
-   if (icon == NULL) return(NULL);
-   /*
-    * Use the text cursor whenever the mouse is in the icon window.
-    */
-   XDefineCursor(dpy, icon, TextCursor);
-    
-   /*
-    * Select "key pressed", "window exposure" and "unmap window"
-    * events for the icon window.
-    */
-   uwmExpressInterest (icon, mask);
-    
-    /*
-     * Set the event window's icon window to be the new icon window.
-     */
-    ptr = (WindowList) malloc(sizeof(WindowListRec));
-    ptr->window = window;
-    ptr->icon = icon;
-    ptr->own = own;
-    ptr->pixmap = background;
-    ptr->next = Icons;
-    Icons = ptr;
+        /*
+         * Select "key pressed", "window exposure" and "unmap window"
+         * events for the icon window.
+         */
+        uwmExpressInterest (icon, mask);
 
-    return(icon);
+        /*
+         * Set the event window's icon window to be the new icon window.
+         */
+        ptr = (WindowList) malloc (sizeof (WindowListRec));
+        ptr->window = window;
+        ptr->icon = icon;
+        ptr->own = own;
+        ptr->pixmap = background;
+        ptr->next = Icons;
+        Icons = ptr;
+
+        return (icon);
 }