This was forwarded to me.  Looks like a cool thing, but I wonder if
that's the sort of thing we want in ctwm.  I'd like to hear your
opinion.

Cheers,
Richard

-----
Please consider sponsoring my work on free software.
See http://www.free.lp.se/sponsoring.html for details.

-- 
Richard Levitte                         [EMAIL PROTECTED]
                                        http://richard.levitte.org/

"When I became a man I put away childish things, including
 the fear of childishness and the desire to be very grown up."
                                                -- C.S. Lewis
--- Begin Message ---
Hello.  I've modified ctwm 3.7 so that I can shift the opacity of my
windows based on the current focus.  I've added two rc file
statements, FocusedOpacity and UnfocusedOpacity, each taking a
numerical value 0-100 to represent the percent opacity for when a
window is focused or unfocused.  I've attached a patch for the
modifications.

--

  ...scott

"There's nothing any of us can do.  We're all screwed."   -Red
Foreman, That 70's Show
diff -u ctwm-3.7/parse.c ctwm-3.7b/parse.c
--- ctwm-3.7/parse.c	2005-06-21 01:35:19.000000000 -0400
+++ ctwm-3.7b/parse.c	2006-10-13 08:57:58.000000000 -0400
@@ -145,6 +145,9 @@
 
 int RaiseDelay = 0;			/* msec, for AutoRaise */
 
+int FocusedOpacity = -1; /* if -1, opacity is unchanged */
+int UnfocusedOpacity = -1;
+
 static int twmStringListInput(void);
 #ifndef USEM4
 static int twmFileInput(void);
@@ -697,6 +700,9 @@
 #define kwn_BorderLeft			35
 #define kwn_BorderRight			36
 
+#define kwn_FocusedOpacity 37
+#define kwn_UnfocusedOpacity 38
+
 #define kwcl_BorderColor		1
 #define kwcl_IconManagerHighlight	2
 #define kwcl_BorderTileForeground	3
@@ -906,6 +912,7 @@
     { "f.warptoscreen",		FSKEYWORD, F_WARPTOSCREEN },
     { "f.winrefresh",		FKEYWORD, F_WINREFRESH },
     { "f.zoom",			FKEYWORD, F_ZOOM },
+    { "focusedopacity", NKEYWORD, kwn_FocusedOpacity },
     { "forceicons",		KEYWORD, kw0_ForceIcons },
     { "frame",			FRAME, 0 },
     { "framepadding",		NKEYWORD, kwn_FramePadding },
@@ -1054,6 +1061,7 @@
     { "titleshadowdepth",	NKEYWORD, kwn_TitleShadowDepth },
     { "transienthasoccupation",	KEYWORD, kw0_TransientHasOccupation },
     { "transientontop",		NKEYWORD, kwn_TransientOnTop },
+    { "unfocusedopacity", NKEYWORD, kwn_UnfocusedOpacity },
     { "unknownicon",		SKEYWORD, kws_UnknownIcon },
     { "unmapbymovingfaraway",	UNMAPBYMOVINGFARAWAY, 0 },
     { "usepposition",		SKEYWORD, kws_UsePPosition },
@@ -1654,6 +1662,14 @@
 	RaiseDelay = num;
 	return 1;
 
+      case kwn_FocusedOpacity:
+  FocusedOpacity = num;
+  return 1;
+
+      case kwn_UnfocusedOpacity:
+  UnfocusedOpacity = num;
+  return 1;
+
       case kwn_TransientOnTop:
 	if (Scr->FirstTime) Scr->TransientOnTop = num;
 	return 1;
diff -u ctwm-3.7/util.c ctwm-3.7b/util.c
--- ctwm-3.7/util.c	2005-06-21 01:35:19.000000000 -0400
+++ ctwm-3.7b/util.c	2006-10-13 13:15:49.000000000 -0400
@@ -226,6 +226,7 @@
    struct timeval AnimateTimeout;
 #endif /* USE_SIGNALS */
 
+
 /***********************************************************************
  *
  *  Procedure:
@@ -1606,6 +1607,8 @@
 void SetFocusVisualAttributes (TwmWindow *tmp_win, Bool focus)
 {
     Bool hil;
+    extern int FocusedOpacity;
+    extern int UnfocusedOpacity;
 
     if (! tmp_win) return;
 
@@ -1664,6 +1667,62 @@
 			tmp_win->title, bs, False, False);
     }
     tmp_win->hasfocusvisible = focus;
+
+  /* FocusedOpacity/UnfocusedOpacity code
+   * Scott McCallum, moskrin at gmail.com
+   * Thanks to Daniel Forchheimer (author of transset-df) for his help with the window parent problem!
+   */
+  {
+  Window parent;
+  Window root;
+  Window child = tmp_win->w;
+  Window *child_list;
+  unsigned int num_children;
+  XQueryTree(dpy, child, &root, &parent, &child_list, &num_children);
+  if( parent == root )
+    parent = child;
+   else
+    {
+    while( parent != root )
+      {
+        child = parent;
+        XQueryTree(dpy, child, &root, &parent, &child_list, &num_children);
+      }
+    }
+  if( focus && FocusedOpacity >= 0 )
+    {
+      unsigned long opacity;
+      double d;
+      d = (double)FocusedOpacity / 100.0;
+      opacity = (unsigned long) (d * 0xffffffff);
+//      fprintf(stderr, "Focus changing opacity of 0x%x to %d%%, 0x%x\n", child, FocusedOpacity, opacity);
+      if( opacity == 0xffffffff )
+        XDeleteProperty(dpy, child, XInternAtom(dpy, "_NET_WM_WINDOW_OPACITY", False));
+       else
+        {
+        XChangeProperty(dpy, child, XInternAtom(dpy, "_NET_WM_WINDOW_OPACITY", False),
+                        XA_CARDINAL, 32, PropModeReplace, (unsigned char *) &opacity, 1L);
+        XSync(dpy, False);
+        }
+    }
+   else if( !focus && UnfocusedOpacity >= 0 )
+    {
+      unsigned int opacity;
+      double d;
+      d = (double)UnfocusedOpacity / 100.0;
+      opacity = (unsigned int) (d * 0xffffffff);
+//      fprintf(stderr, "Unfocus changing opacity of 0x%x to %d%%, 0x%x\n", child, UnfocusedOpacity, opacity);
+      if( opacity == 0xffffffff )
+        XDeleteProperty(dpy, child, XInternAtom(dpy, "_NET_WM_WINDOW_OPACITY", False));
+       else
+        {
+        XChangeProperty(dpy, child, XInternAtom(dpy, "_NET_WM_WINDOW_OPACITY", False),
+                        XA_CARDINAL, 32, PropModeReplace, (unsigned char *) &opacity, 1L);
+        XSync(dpy, False);
+        }
+
+    }
+  } // end FocusedOpacity/UnfocusedOpacity handling
 }
 
 static void move_to_head (TwmWindow *t)

--- End Message ---

Reply via email to