summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArnaud Fontaine <arnau@debian.org>2011-10-30 20:33:40 +0900
committerArnaud Fontaine <arnau@debian.org>2011-12-14 20:07:59 +0900
commit8605d0178461b98099c5dee33b19eb8204487487 (patch)
treeab5b89f4e83730e559cac9f43de1b6227189e5d0
parente4d0f93a64dbb9b77ee6a32dcf85ce1b65449e9d (diff)
Fix coding style.
-rw-r--r--dsimple.c393
-rw-r--r--dsimple.h16
-rw-r--r--transSet.c552
3 files changed, 499 insertions, 462 deletions
diff --git a/dsimple.c b/dsimple.c
index ab7a87f..331f1bc 100644
--- a/dsimple.c
+++ b/dsimple.c
@@ -1,29 +1,29 @@
/* $Xorg: dsimple.c,v 1.4 2001/02/09 02:05:54 xorgcvs Exp $ */
/*
-Copyright 1993, 1998 The Open Group
-
-Permission to use, copy, modify, distribute, and sell this software and its
-documentation for any purpose is hereby granted without fee, provided that
-the above copyright notice appear in all copies and that both that
-copyright notice and this permission notice appear in supporting
-documentation.
-
-The above copyright notice and this permission notice shall be included
-in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
-OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
-ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-
-Except as contained in this notice, the name of The Open Group shall
-not be used in advertising or otherwise to promote the sale, use or
-other dealings in this Software without prior written authorization
-from The Open Group.
+ Copyright 1993, 1998 The Open Group
+
+ Permission to use, copy, modify, distribute, and sell this software and its
+ documentation for any purpose is hereby granted without fee, provided that
+ the above copyright notice appear in all copies and that both that
+ copyright notice and this permission notice appear in supporting
+ documentation.
+
+ The above copyright notice and this permission notice shall be included
+ in all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ OTHER DEALINGS IN THE SOFTWARE.
+
+ Except as contained in this notice, the name of The Open Group shall
+ not be used in advertising or otherwise to promote the sale, use or
+ other dealings in this Software without prior written authorization
+ from The Open Group.
*/
/* $XFree86: xc/programs/xlsfonts/dsimple.c,v 3.6 2001/12/14 20:02:09 dawes Exp $ */
@@ -64,29 +64,31 @@ int screen;
* Get_Display_Name (argc, argv) Look for -display, -d, or host:dpy (obselete)
* If found, remove it from command line. Don't go past a lone -.
*/
-static char *Get_Display_Name(int *pargc, char **argv)
+static char *
+Get_Display_Name (int *pargc, char **argv)
{
int argc = *pargc;
- char **pargv = argv+1;
+ char **pargv = argv + 1;
char *displayname = NULL;
int i;
for (i = 1; i < argc; i++) {
- char *arg = argv[i];
-
- if (!strcmp (arg, "-display") || !strcmp (arg, "-d")) {
- if (++i >= argc) usage ();
-
- displayname = argv[i];
- *pargc -= 2;
- continue;
- }
- if (!strcmp(arg,"-")) {
- while (i<argc)
- *pargv++ = argv[i++];
- break;
- }
- *pargv++ = arg;
+ char *arg = argv[i];
+
+ if (!strcmp (arg, "-display") || !strcmp (arg, "-d")) {
+ if (++i >= argc)
+ Usage ();
+
+ displayname = argv[i];
+ *pargc -= 2;
+ continue;
+ }
+ if (!strcmp (arg, "-")) {
+ while (i <argc)
+ *pargv++ = argv[i++];
+ break;
+ }
+ *pargv++ = arg;
}
*pargv = NULL;
@@ -98,19 +100,19 @@ static char *Get_Display_Name(int *pargc, char **argv)
* Open_Display: Routine to open a display with correct error handling.
* Does not require dpy or screen defined on entry.
*/
-static Display *Open_Display(char *display_name)
+static Display *
+Open_Display (char *display_name)
{
- Display *d;
+ Display *d;
- d = XOpenDisplay(display_name);
- if (d == NULL) {
- fprintf (stderr, "%s: unable to open display '%s'\n",
- program_name, XDisplayName (display_name));
- usage ();
- /* doesn't return */
- }
+ d = XOpenDisplay (display_name);
+ if (d == NULL) {
+ fprintf (stderr, "%s: unable to open display '%s'\n",
+ program_name, XDisplayName (display_name));
+ Usage ();
+ }
- return(d);
+ return (d);
}
@@ -121,10 +123,11 @@ static Display *Open_Display(char *display_name)
* for this display is then stored in screen.
* Does not require dpy or screen defined.
*/
-void Setup_Display_And_Screen(int *argc, char **argv)
+void
+Setup_Display_And_Screen (int *argc, char **argv)
{
- dpy = Open_Display (Get_Display_Name(argc, argv));
- screen = DefaultScreen(dpy);
+ dpy = Open_Display (Get_Display_Name (argc, argv));
+ screen = DefaultScreen (dpy);
}
/*
@@ -137,63 +140,67 @@ void Setup_Display_And_Screen(int *argc, char **argv)
* Standard fatal error routine - call like printf but maximum of 7 arguments.
* Does not require dpy or screen defined.
*/
-void Fatal_Error(char *msg, ...)
+void
+Fatal_Error (char *msg, ...)
{
- va_list args;
- fflush(stdout);
- fflush(stderr);
- fprintf(stderr, "%s: error: ", program_name);
- va_start(args, msg);
- vfprintf(stderr, msg, args);
- va_end(args);
- fprintf(stderr, "\n");
- exit(1);
+ va_list args;
+ fflush (stdout);
+ fflush (stderr);
+ fprintf (stderr, "%s: error: ", program_name);
+ va_start (args, msg);
+ vfprintf (stderr, msg, args);
+ va_end (args);
+ fprintf (stderr, "\n");
+ exit (1);
}
/*
* Routine to let user select a window using the mouse
*/
-Window Select_Window(Display *dpy)
+Window
+Select_Window (Display *dpy)
{
- int status;
- Cursor cursor;
- XEvent event;
- Window target_win = None, root = RootWindow(dpy,screen);
- int buttons = 0;
-
- /* Make the target cursor */
- cursor = XCreateFontCursor(dpy, XC_crosshair);
-
- /* Grab the pointer using target cursor, letting it room all over */
- status = XGrabPointer(dpy, root, False,
- ButtonPressMask|ButtonReleaseMask, GrabModeSync,
- GrabModeAsync, root, cursor, CurrentTime);
- if (status != GrabSuccess) Fatal_Error("Can't grab the mouse.");
-
- /* Let the user select a window... */
- while ((target_win == None) || (buttons != 0)) {
- /* allow one more event */
- XAllowEvents(dpy, SyncPointer, CurrentTime);
- XWindowEvent(dpy, root, ButtonPressMask|ButtonReleaseMask, &event);
- switch (event.type) {
- case ButtonPress:
- if (target_win == None) {
- target_win = event.xbutton.subwindow; /* window selected */
- if (target_win == None) target_win = root;
- }
- buttons++;
- break;
- case ButtonRelease:
- if (buttons > 0) /* there may have been some down before we started */
- buttons--;
- break;
+ int status;
+ Cursor cursor;
+ XEvent event;
+ Window target_win = None, root = RootWindow (dpy, screen);
+ int buttons = 0;
+
+ /* Make the target cursor */
+ cursor = XCreateFontCursor (dpy, XC_crosshair);
+
+ /* Grab the pointer using target cursor, letting it room all over */
+ status = XGrabPointer (dpy, root, False,
+ ButtonPressMask|ButtonReleaseMask, GrabModeSync,
+ GrabModeAsync, root, cursor, CurrentTime);
+ if (status != GrabSuccess)
+ Fatal_Error ("Can't grab the mouse.");
+
+ /* Let the user select a window... */
+ while ((target_win == None) || (buttons != 0)) {
+ /* allow one more event */
+ XAllowEvents (dpy, SyncPointer, CurrentTime);
+ XWindowEvent (dpy, root, ButtonPressMask | ButtonReleaseMask, &event);
+ switch (event.type) {
+ case ButtonPress:
+ if (target_win == None) {
+ target_win = event.xbutton.subwindow; /* window selected */
+ if (target_win == None)
+ target_win = root;
+ }
+ buttons++;
+ break;
+ case ButtonRelease:
+ if (buttons > 0) /* there may have been some down before we started */
+ buttons--;
+ break;
+ }
}
- }
- XUngrabPointer(dpy, CurrentTime); /* Done with pointer */
+ XUngrabPointer (dpy, CurrentTime); /* Done with pointer */
- return(target_win);
+ return (target_win);
}
/*
@@ -201,36 +208,37 @@ Window Select_Window(Display *dpy)
* Added by Daniel Forchheimer. Last updated 19/12/04
*/
-Window Get_Window_Under_Cursor(Display *dpy)
+Window
+Get_Window_Under_Cursor (Display *dpy)
{
- int status;
- Cursor cursor;
- //XEvent event;
- Window target_win = None, root = RootWindow(dpy,screen);
- //int buttons = 0;
- Window tmp;
- int rx,ry,cx,cy;
- unsigned int mask;
-
- /* Make the target cursor */
- cursor = XCreateFontCursor(dpy, XC_crosshair);
-
- /* Grab the pointer using target cursor, letting it room all over */
- status = XGrabPointer(dpy, root, False,
- ButtonPressMask|ButtonReleaseMask, GrabModeSync,
- GrabModeAsync, root, cursor, CurrentTime);
- if (status != GrabSuccess) Fatal_Error("Can't grab the mouse.");
-
- /* get the window under the cursor */
- XQueryPointer(dpy, root, &tmp, &target_win, &rx, &ry,
- &cx, &cy, &mask);
-
- XUngrabPointer(dpy, CurrentTime); /* Done with pointer */
-
- return(target_win);
+ int status;
+ Cursor cursor;
+ //XEvent event;
+ Window target_win = None, root = RootWindow (dpy, screen);
+ //int buttons = 0;
+ Window tmp;
+ int rx, ry, cx, cy;
+ unsigned int mask;
+
+ /* Make the target cursor */
+ cursor = XCreateFontCursor (dpy, XC_crosshair);
+
+ /* Grab the pointer using target cursor, letting it room all over */
+ status = XGrabPointer (dpy, root, False,
+ ButtonPressMask|ButtonReleaseMask, GrabModeSync,
+ GrabModeAsync, root, cursor, CurrentTime);
+ if (status != GrabSuccess)
+ Fatal_Error ("Can't grab the mouse.");
+
+ /* get the window under the cursor */
+ XQueryPointer (dpy, root, &tmp, &target_win, &rx, &ry,
+ &cx, &cy, &mask);
+
+ XUngrabPointer (dpy, CurrentTime); /* Done with pointer */
+
+ return (target_win);
}
-
/*
* Window_With_Name: routine to locate a window with a given name on a display.
* If no window with the given name is found, 0 is returned.
@@ -238,82 +246,89 @@ Window Get_Window_Under_Cursor(Display *dpy)
* one found will be returned. Only top and its subwindows
* are looked at. Normally, top should be the RootWindow.
*/
-Window Window_With_Name(Display *dpy, Window top, char *name)
+Window
+Window_With_Name (Display *dpy, Window top, char *name)
{
- Window *children, dummy;
- unsigned int nchildren;
- int i;
- Window w=0;
- char *window_name;
-
- if (XFetchName(dpy, top, &window_name) && !strcmp(window_name, name))
- return(top);
-
- if (!XQueryTree(dpy, top, &dummy, &dummy, &children, &nchildren))
- return(0);
-
- for (i=0; i<nchildren; i++) {
- w = Window_With_Name(dpy, children[i], name);
- if (w)
- break;
- }
- if (children) XFree ((char *)children);
- return(w);
+ Window *children, dummy;
+ unsigned int nchildren;
+ int i;
+ Window w = 0;
+ char *window_name;
+
+ if (XFetchName (dpy, top, &window_name) && !strcmp (window_name, name))
+ return (top);
+
+ if (!XQueryTree (dpy, top, &dummy, &dummy, &children, &nchildren))
+ return (0);
+
+ for (i = 0; i < nchildren; i++) {
+ w = Window_With_Name (dpy, children[i], name);
+ if (w)
+ break;
+ }
+ if (children)
+ XFree ((char *) children);
+ return (w);
}
/*
* Window_With_Name_Regex: Same as above but use regular expressions
* to match a window name. Only returns the first
* result.
- * Window_With_Name_Regex_Recurse: Takes regex_t struct as argument
- * instead of char*
+ * Window_With_Name_Regex_Recurse: Takes regex_t struct as argument instead of char*
* Written by Daniel Forchheimer 2005
* */
-static Window Window_With_Name_Regex_Recurse(Display *dpy, Window top,
- regex_t *reg_name)
+static Window
+Window_With_Name_Regex_Recurse (Display *dpy, Window top,
+ regex_t *reg_name)
{
- Window *children, dummy;
- unsigned int nchildren;
- int i;
- Window w=0;
- char *window_name;
-
- if (XFetchName(dpy, top, &window_name) && !regexec(reg_name,window_name,0,NULL,0))
- return(top);
-
- if (!XQueryTree(dpy, top, &dummy, &dummy, &children, &nchildren))
- return(0);
-
- for (i=0; i<nchildren; i++) {
- w = Window_With_Name_Regex_Recurse(dpy, children[i], reg_name);
- if (w)
- break;
- }
- if (children) XFree ((char *)children);
- return(w);
+ Window *children, dummy;
+ unsigned int nchildren;
+ int i;
+ Window w = 0;
+ char *window_name;
+
+ if (XFetchName (dpy, top, &window_name) &&
+ !regexec (reg_name, window_name, 0, NULL, 0))
+ return (top);
+
+ if (!XQueryTree (dpy, top, &dummy, &dummy, &children, &nchildren))
+ return (0);
+
+ for (i = 0; i < nchildren; i++) {
+ w = Window_With_Name_Regex_Recurse (dpy, children[i], reg_name);
+ if (w)
+ break;
+ }
+ if (children)
+ XFree ((char *) children);
+ return (w);
}
+
/* prepare the reg-exp for use with above function */
-Window Window_With_Name_Regex(Display *dpy, Window top, char *name)
+Window
+Window_With_Name_Regex (Display *dpy, Window top, char *name)
{
- int err_no=0;
- regex_t *regexp_name;
- Window target_win;
- regexp_name = (regex_t *) malloc(sizeof(regex_t));
- if((err_no=regcomp(regexp_name, name, 0))!=0)
- {
- size_t length;
- char *buffer;
- length = regerror (err_no, regexp_name, NULL, 0);
- buffer = malloc(length);
- regerror (err_no, regexp_name, buffer, length);
- fprintf(stderr, "%s\n", buffer);
- free(buffer);
- regfree(regexp_name);
- exit(1);
+ int err_no = 0;
+ regex_t *regexp_name;
+ Window target_win;
+ regexp_name = (regex_t *) malloc (sizeof (regex_t));
+ if ((err_no = regcomp (regexp_name, name, 0)) != 0) {
+ size_t length;
+ char *buffer;
+ length = regerror (err_no, regexp_name, NULL, 0);
+ buffer = malloc (length);
+ regerror (err_no, regexp_name, buffer, length);
+ fprintf (stderr, "%s\n", buffer);
+ free (buffer);
+ regfree (regexp_name);
+ exit (1);
}
- target_win = Window_With_Name_Regex_Recurse(dpy, RootWindow(dpy, screen),regexp_name);
+ target_win = Window_With_Name_Regex_Recurse (dpy,
+ RootWindow (dpy, screen),
+ regexp_name);
- regfree(regexp_name);
- free(regexp_name);
- return target_win;
+ regfree (regexp_name);
+ free (regexp_name);
+ return target_win;
}
diff --git a/dsimple.h b/dsimple.h
index f259fe3..a82d3cb 100644
--- a/dsimple.h
+++ b/dsimple.h
@@ -48,8 +48,8 @@ extern int screen; /* The current screen */
#define INIT_NAME program_name=argv[0] /* use this in main to setup
program_name */
-void Setup_Display_And_Screen(int *, char **);
-void usage(void);
+void Setup_Display_And_Screen (int *, char **);
+void Usage (void);
#define X_USAGE "[host:display]" /* X arguments handled by
Get_Display_Name */
@@ -62,12 +62,12 @@ void usage(void);
* Send bugs, etc. to chariot@athena.mit.edu.
*/
-Window Select_Window(Display *);
-Window Get_Window_Under_Cursor(Display *); /*added by Daniel Forchheimer for transset-df*/
-Window Window_With_Name(Display *, Window, char *);
-Window Window_With_Name_Regex(Display *, Window, char *); /*added by Daniel Forchheimer for transset-df*/
+Window Select_Window (Display *);
+Window Get_Window_Under_Cursor (Display *); /*added by Daniel Forchheimer for transset-df*/
+Window Window_With_Name (Display *, Window, char *);
+Window Window_With_Name_Regex (Display *, Window, char *); /*added by Daniel Forchheimer for transset-df*/
#ifdef __GNUC__
-void Fatal_Error(char *, ...) __attribute__((__noreturn__));
+void Fatal_Error (char *, ...) __attribute__((__noreturn__));
#else
-void Fatal_Error(char *, ...);
+void Fatal_Error (char *, ...);
#endif
diff --git a/transSet.c b/transSet.c
index b988ba4..b44c392 100644
--- a/transSet.c
+++ b/transSet.c
@@ -1,14 +1,14 @@
/* Simple program to toggle Translucency property
Based on 'transset' by Matthew Hawn
With some additional features to make it more automatic and integrated
- The purpos is to bind it from your wm to a key or mouse-button
+ The purpose is to bind it from your wm to a key or mouse-button
License: Use however you want.
- Authors:
- Matthew Hawn
- Daniel Forchheimer
- Andreas Kohn
- Roman Divacky
+ Authors:
+ Matthew Hawn
+ Daniel Forchheimer
+ Andreas Kohn
+ Roman Divacky
*/
#define VERSIONSTR "6"
@@ -28,281 +28,303 @@ Window target_win;
/* needed by dsimple.c */
-void usage(void)
+void
+Usage (void)
{
- fprintf(stderr,"usage: transset-df [-options ...] [opacity]\n");
- fprintf(stderr,"options:\n");
-
- fprintf(stderr,
- " -h, --help display this message\n");
- fprintf(stderr,
- " -t, --toggle force toggle of opacity\n");
- fprintf(stderr,
- " -c, --click select by clicking on window (default)\n");
- fprintf(stderr,
- " -p, --point select the window currently under the cursor\n");
- fprintf(stderr,
- " -a, --actual select the actual window\n");
- fprintf(stderr,
- " -n, --name NAME select by name, NAME is matched as regular expression\n");
- fprintf(stderr,
- " --no-regex don't use regular expression for matching name\n");
- fprintf(stderr,
- " -i, --id select by window id\n");
- fprintf(stderr,
- " --inc increase by the given opacity\n");
- fprintf(stderr,
- " --dec decrease by given opacity\n");
- fprintf(stderr,
- " -m, --min OPACITY minimum possible opacity (default = 0)\n");
- fprintf(stderr,
- " -x, --max OPACITY maximum possible opacity (default = 1)\n");
- fprintf(stderr,
- " -v, --verbose print some debug info\n");
- fprintf(stderr,
- " -V, --version print version number\n");
-
- exit(1);
+ fprintf (stderr, "usage: transset-df [-options ...] [opacity]\n");
+ fprintf (stderr, "options:\n");
+
+ fprintf (stderr,
+ " -h, --help display this message\n");
+ fprintf (stderr,
+ " -t, --toggle force toggle of opacity\n");
+ fprintf (stderr,
+ " -c, --click select by clicking on window (default)\n");
+ fprintf (stderr,
+ " -p, --point select the window currently under the cursor\n");
+ fprintf (stderr,
+ " -a, --actual select the actual window\n");
+ fprintf (stderr,
+ " -n, --name NAME select by name, NAME is matched as regular expression\n");
+ fprintf (stderr,
+ " --no-regex don't use regular expression for matching name\n");
+ fprintf (stderr,
+ " -i, --id select by window id\n");
+ fprintf (stderr,
+ " --inc increase by the given opacity\n");
+ fprintf (stderr,
+ " --dec decrease by given opacity\n");
+ fprintf (stderr,
+ " -m, --min OPACITY minimum possible opacity (default = 0)\n");
+ fprintf (stderr,
+ " -x, --max OPACITY maximum possible opacity (default = 1)\n");
+ fprintf (stderr,
+ " -v, --verbose print some debug info\n");
+ fprintf (stderr,
+ " -V, --version print version number\n");
+
+ exit (1);
}
#define OPAQUE 0xffffffff
#define OPACITY "_NET_WM_WINDOW_OPACITY"
/* returns the highest parent of child that is not the root-window */
-static Window get_top_window(Display *dpy,Window child) {
- Window parent;
- Window root;
- Window *child_list;
- unsigned int num_children;
-
- if (!XQueryTree(dpy, child, &root, &parent, &child_list,
- &num_children))
- Fatal_Error("Can't query window tree.");
- if(parent==root) return child;
-
- while(parent!=root) {
- child = parent;
- if (!XQueryTree(dpy, child, &root, &parent, &child_list,
- &num_children))
- Fatal_Error("Can't query window tree.");
-
- }
- return child;
+static Window
+Get_Top_Window (Display *dpy, Window child) {
+ Window parent;
+ Window root;
+ Window *child_list;
+ unsigned int num_children;
+
+ if (!XQueryTree (dpy, child, &root, &parent, &child_list,
+ &num_children))
+ Fatal_Error ("Can't query window tree.");
+
+ if (parent == root)
+ return child;
+
+ while (parent != root) {
+ child = parent;
+ if (!XQueryTree (dpy, child, &root, &parent, &child_list,
+ &num_children))
+ Fatal_Error ("Can't query window tree.");
+
+ }
+ return child;
}
-/* returns the actual window */
-static Window get_actual_window(Display *dpy)
+static Window
+Get_Actual_Window (Display *dpy)
{
int i;
Window w;
- XGetInputFocus(dpy, &w, &i);
- return get_top_window(dpy, w);
+ XGetInputFocus (dpy, &w, &i);
+ return Get_Top_Window (dpy, w);
}
-/* nothing fancy */
-int main(int argc, char **argv)
+int
+main (int argc, char **argv)
{
- int gotd = 0;
- double d;
- unsigned int opacity;
- unsigned int current_opacity;
- int select_method = 0; // 0 = click, 1 = point, 2 = id, 3 = name
- int flag_toggle=0;
- int flag_increase=0;
- int flag_decrease=0;
- int flag_verbose=0;
- int flag_no_regex=0;
- int o;
- float min=0,max=1;
- char *idstr,*namestr;
- char *windowname=NULL;
-
- int options_index=0;
- static struct option long_options[] = {
- {"toggle",0,NULL,'t'},
- {"help",0,NULL,'h'},
- {"point",0,NULL,'p'},
- {"actual",0,NULL,'a'},
- {"click",0,NULL,'c'},
- {"id",1,NULL,'i'},
- {"name",1,NULL,'n'},
- {"inc",0,NULL,'1'},
- {"dec",0,NULL,'2'},
- {"min",1,NULL,'m'},
- {"max",1,NULL,'x'},
- {"no-regex",0,NULL,'4'},
- {"version",0,NULL,'V'},
- {"verbose",0,NULL,'v'},
- {0,0,0,0}
- };
- unsigned char *data;
-
- Atom actual;
- int format;
- unsigned long n, left;
-
- /* wonderful utility */
- Setup_Display_And_Screen(&argc, argv);
-
- /* parse arguments */
- while ((o = getopt_long(argc, argv, "thapci:n:vVm:x:123",long_options,&options_index)) != -1)
- {
- switch (o) {
- case 't':
- flag_toggle=1;
- break;
- case 'h':
- usage();
- break;
- case 'c':
- select_method=0;
- break;
- case 'p':
- select_method=1;
- break;
- case 'i':
- idstr = malloc(strlen(optarg)+1);
- idstr = optarg;
- select_method=2;
- break;
- case 'n':
- namestr = malloc(strlen(optarg)+1);
- namestr = optarg;
- select_method=3;
- break;
- case 'a':
- select_method=4;
- break;
- case '1':
- flag_increase=1;
- break;
- case '2':
- flag_decrease=1;
- break;
- case 'v':
- flag_verbose=1;
- break;
- case '4':
- flag_no_regex=1;
- break;
- case 'm':
- min = atof(optarg);
- break;
- case 'x':
- max = atof(optarg);
- break;
- case 'V':
- fprintf(stderr,"version: %s\nreleased: %s\n",VERSIONSTR,RELEASEDATESTR);
- exit(1);
- break;
- default:
- usage();
- }
+ int gotd = 0;
+ double d;
+ unsigned int opacity;
+ unsigned int current_opacity;
+ int select_method = 0; // 0 = click, 1 = point, 2 = id, 3 = name
+ int flag_toggle = 0;
+ int flag_increase = 0;
+ int flag_decrease = 0;
+ int flag_verbose = 0;
+ int flag_no_regex = 0;
+ int o;
+ float min = 0, max = 1;
+ char *idstr, *namestr;
+ char *windowname = NULL;
+
+ int options_index = 0;
+ static struct option long_options[] = {
+ {"toggle", 0, NULL, 't'},
+ {"help", 0, NULL, 'h'},
+ {"point", 0, NULL, 'p'},
+ {"actual", 0, NULL, 'a'},
+ {"click", 0, NULL, 'c'},
+ {"id", 1, NULL, 'i'},
+ {"name", 1, NULL, 'n'},
+ {"inc", 0, NULL, '1'},
+ {"dec", 0, NULL, '2'},
+ {"min", 1, NULL, 'm'},
+ {"max", 1, NULL, 'x'},
+ {"no-regex", 0, NULL, '4'},
+ {"version", 0, NULL, 'V'},
+ {"verbose", 0, NULL, 'v'},
+ {0, 0, 0, 0}
+ };
+ unsigned char *data;
+
+ Atom actual;
+ int format;
+ unsigned long n, left;
+
+ /* wonderful utility */
+ Setup_Display_And_Screen (&argc, argv);
+
+ /* parse arguments */
+ while ((o = getopt_long (argc, argv, "thapci:n:vVm:x:123",
+ long_options, &options_index)) != -1) {
+ switch (o) {
+ case 't':
+ flag_toggle = 1;
+ break;
+ case 'h':
+ Usage ();
+ break;
+ case 'c':
+ select_method = 0;
+ break;
+ case 'p':
+ select_method = 1;
+ break;
+ case 'i':
+ idstr = malloc (strlen (optarg) + 1);
+ idstr = optarg;
+ select_method = 2;
+ break;
+ case 'n':
+ namestr = malloc (strlen (optarg) + 1);
+ namestr = optarg;
+ select_method = 3;
+ break;
+ case 'a':
+ select_method = 4;
+ break;
+ case '1':
+ flag_increase = 1;
+ break;
+ case '2':
+ flag_decrease = 1;
+ break;
+ case 'v':
+ flag_verbose = 1;
+ break;
+ case '4':
+ flag_no_regex = 1;
+ break;
+ case 'm':
+ min = atof (optarg);
+ break;
+ case 'x':
+ max = atof (optarg);
+ break;
+ case 'V':
+ fprintf (stderr, "version: %s\nreleased: %s\n",
+ VERSIONSTR, RELEASEDATESTR);
+ exit (1);
+ break;
+ default:
+ Usage ();
+ }
+ }
+
+ if (optind < argc) {
+ d = atof (argv[optind]);
+ gotd = 1;
}
-
- if(optind<argc)
- {
- d = atof (argv[optind]);
- gotd = 1;
- }
-
- /* select the window to make transparent */
- if(select_method==1) {
- /* don't wait for click */
- if(flag_verbose) printf("Selecting window by click\n");
- target_win = Get_Window_Under_Cursor(dpy);
- } else if(select_method==2) {
- /* select by id, pretty much ripped from dsimple.c */
- if(flag_verbose) printf("Selecting window by id\n");
- sscanf(idstr, "0x%lx", &target_win);
- if (!target_win)
- sscanf(idstr, "%ld", &target_win);
- if (!target_win) {
- fprintf(stderr,"Invalid window id format: %s.\n", idstr);
- exit(0);
- }
- if(flag_verbose) printf("Selected 0x%x, trying to get top parent ... ",(unsigned int)target_win);
- target_win = get_top_window(dpy,target_win);
- if(flag_verbose) printf("found 0x%x\n",(unsigned int)target_win);
-
- } else if(select_method==3) {
- /* select by name, pretty much ripped from dsimple.c */
- if(flag_verbose) printf("Selecting window by name\n");
-
- if(flag_no_regex)
- target_win = Window_With_Name(dpy, RootWindow(dpy, screen),namestr);
- else
- target_win = Window_With_Name_Regex(dpy, RootWindow(dpy, screen),namestr);
-
- if (!target_win) {
- fprintf(stderr,"No window matching %s exists!\n",namestr);
- exit(0);
- }
- /* store the matched window name*/
- XFetchName(dpy,target_win,&windowname);
-
- if(flag_verbose) printf("Selected 0x%x, trying to get top parent ... ",(unsigned int)target_win);
- target_win = get_top_window(dpy,target_win);
- if(flag_verbose) printf("found 0x%x\n",(unsigned int)target_win);
-
- } else if(select_method==4) {
- target_win = get_actual_window(dpy);
- } else {
- /* grab mouse and return window that is next clicked */
- target_win = Select_Window(dpy);
- }
-
- if (!gotd) d=0.75;
-
- /* get property */
- XGetWindowProperty(dpy, target_win, XInternAtom(dpy, OPACITY, False),
- 0L, 1L, False, XA_CARDINAL, &actual, &format, &n, &left,
- (unsigned char **) &data);
-
- if (data != None)
- {
- memcpy (&current_opacity, data, sizeof (unsigned int));
- XFree(( void *) data );
- if(flag_verbose) printf("Found transparency: %g\n", (double) opacity / OPAQUE);
+
+ /* select the window to make transparent */
+ if (select_method == 1) {
+ /* don't wait for click */
+ if (flag_verbose)
+ printf ("Selecting window by click\n");
+ target_win = Get_Window_Under_Cursor (dpy);
+ } else if (select_method == 2) {
+ /* select by id, pretty much ripped from dsimple.c */
+ if (flag_verbose)
+ printf ("Selecting window by id\n");
+ sscanf (idstr, "0x%lx", &target_win);
+ if (!target_win)
+ sscanf (idstr, "%ld", &target_win);
+ if (!target_win) {
+ fprintf (stderr, "Invalid window id format: %s.\n", idstr);
+ exit (0);
+ }
+ if (flag_verbose)
+ printf ("Selected 0x%x, trying to get top parent ... ",
+ (unsigned int) target_win);
+ target_win = Get_Top_Window (dpy, target_win);
+ if (flag_verbose)
+ printf ("found 0x%x\n", (unsigned int) target_win);
+
+ } else if (select_method == 3) {
+ /* select by name, pretty much ripped from dsimple.c */
+ if (flag_verbose)
+ printf ("Selecting window by name\n");
+
+ if (flag_no_regex)
+ target_win = Window_With_Name (dpy, RootWindow (dpy, screen),
+ namestr);
+ else
+ target_win = Window_With_Name_Regex (dpy, RootWindow (dpy, screen),
+ namestr);
+
+ if (!target_win) {
+ fprintf (stderr, "No window matching %s exists!\n", namestr);
+ exit (0);
+ }
+ /* store the matched window name*/
+ XFetchName (dpy, target_win, &windowname);
+
+ if (flag_verbose)
+ printf ("Selected 0x%x, trying to get top parent ... ",
+ (unsigned int) target_win);
+
+ target_win = Get_Top_Window (dpy, target_win);
+ if (flag_verbose)
+ printf ("found 0x%x\n", (unsigned int) target_win);
+
+ } else if (select_method == 4) {
+ target_win = Get_Actual_Window (dpy);
+ } else {
+ /* grab mouse and return window that is next clicked */
+ target_win = Select_Window (dpy);
}
- else
- current_opacity = OPAQUE;
-
- if(flag_increase) {
- d = (double)current_opacity/OPAQUE + d;
- } else if(flag_decrease) {
- d = (double)current_opacity/OPAQUE - d;
- }
- //printf("%f\n",d);
- /* check min and max */
- if(d<min) d=min;
- if(d>max) d=max;
-
- opacity = (unsigned int) (d * OPAQUE);
-
- /* for user-compability with transset */
- if(!gotd) flag_toggle=1;
-
- /* toggle */
- if(flag_toggle)
- if (current_opacity != OPAQUE)
- opacity = OPAQUE;
-
- // printf ("opacity 0x%x\n", opacity);
- if (opacity == OPAQUE)
- XDeleteProperty (dpy, target_win, XInternAtom(dpy, OPACITY, False));
- /* set it */
- else
- XChangeProperty(dpy, target_win, XInternAtom(dpy, OPACITY, False),
- XA_CARDINAL, 32, PropModeReplace,
- (unsigned char *) &opacity, 1L);
- XSync(dpy, False);
-
- printf("Set Property to %g", (double) opacity / OPAQUE);
- if(windowname) printf(" on \n%s\n",windowname);
- else printf("\n");
- if(flag_verbose) printf("Propery set on: 0x%x\n",(unsigned int)target_win);
- /* all done, wasn't that simple */
- return 0;
+
+ if (!gotd)
+ d = 0.75;
+
+ /* get property */
+ XGetWindowProperty (dpy, target_win, XInternAtom (dpy, OPACITY, False),
+ 0L, 1L, False, XA_CARDINAL, &actual, &format, &n, &left,
+ (unsigned char **) &data);
+
+ if (data != None) {
+ memcpy (&current_opacity, data, sizeof (unsigned int));
+ XFree ((void *) data);
+ if (flag_verbose)
+ printf ("Found transparency: %g\n",
+ (double) opacity / OPAQUE);
+ } else
+ current_opacity = OPAQUE;
+
+ if (flag_increase)
+ d = (double) current_opacity / OPAQUE + d;
+ else if (flag_decrease)
+ d = (double) current_opacity / OPAQUE - d;
+
+ /* check min and max */
+ if (d < min)
+ d = min;
+ if (d > max)
+ d = max;
+
+ opacity = (unsigned int) (d * OPAQUE);
+
+ /* for user-compability with transset */
+ if (!gotd)
+ flag_toggle = 1;
+
+ /* toggle */
+ if (flag_toggle)
+ if (current_opacity != OPAQUE)
+ opacity = OPAQUE;
+
+ if (opacity == OPAQUE)
+ XDeleteProperty (dpy, target_win, XInternAtom (dpy, OPACITY, False));
+ /* set it */
+ else
+ XChangeProperty (dpy, target_win, XInternAtom (dpy, OPACITY, False),
+ XA_CARDINAL, 32, PropModeReplace,
+ (unsigned char *) &opacity, 1L);
+ XSync (dpy, False);
+
+ printf ("Set Property to %g", (double) opacity / OPAQUE);
+ if (windowname)
+ printf (" on \n%s\n", windowname);
+ else
+ printf ("\n");
+
+ if (flag_verbose)
+ printf ("Propery set on: 0x%x\n", (unsigned int) target_win);
+
+ return 0;
}