summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArnaud Fontaine <arnau@debian.org>2011-10-30 16:40:04 +0900
committerArnaud Fontaine <arnau@debian.org>2011-10-30 16:40:04 +0900
commit55a5a8da9b0a2b997096319e8d990a70ee31ac94 (patch)
tree3625a712ea33bbcf11d058c0975ab63b8eb639ef
parent705d787a5b35a8409c482526b5c2955aa5371b1e (diff)
2005-01-13 Daniel Forchheimer <n04df@efd.lth.se>
* transSet.c: (main): Forked transset-df of transset Added flags Added select without clicking Wrote usage * dsimple.c: Added function to select without clicking
-rw-r--r--README26
-rw-r--r--dsimple.c35
-rw-r--r--transSet.c133
3 files changed, 158 insertions, 36 deletions
diff --git a/README b/README
new file mode 100644
index 0000000..c234a3b
--- /dev/null
+++ b/README
@@ -0,0 +1,26 @@
+This is a patched version of xorg's transset
+I wanted to integrate transset into my windowmanager and to
+be able to set and unset transparency by just pressing a key.
+To make that possible I didn't want transset to wait for me to
+click on a window but instead setting transparency immidietly on
+the window under the cursor.
+
+In the future I guess it's ment for the windowmanagers to handle
+transparency. Then we will hopefully see this function and many other
+now imposible functions (like opacity following the mousepointer).
+But this will require you to wait untill this is implementet in
+your favorite wm. This patch is my way of "scratching where it itches",
+with only minor changes transset can now be used with any windowmanager
+to make it do somethink actually usefull.
+
+Features
+ -select window by clicking (as transset)
+ -select window by pointing
+ -force toggle
+
+
+Any questions/sugestions just send me a email
+
+Cheers
+Daniel Forchheimer (upiom)
+n04df@efd.lth.se
diff --git a/dsimple.c b/dsimple.c
index bbdbd93..e388380 100644
--- a/dsimple.c
+++ b/dsimple.c
@@ -450,6 +450,41 @@ Window Select_Window(dpy)
return(target_win);
}
+/*
+ * Routine that returns the window currently under the cursor
+ * Added by Daniel Forchheimer. Last updated 19/12/04
+ */
+
+Window Get_Window_Under_Cursor(dpy)
+ 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);
+}
+
/*
* Window_With_Name: routine to locate a window with a given name on a display.
diff --git a/transSet.c b/transSet.c
index fe7d0b9..8437f2c 100644
--- a/transSet.c
+++ b/transSet.c
@@ -1,18 +1,21 @@
-/* Simple program to toggle Translucency property on next window clicked
- Uses dsimple.h and dsimple.c from xlsfonts.
- Based on xprops and xwininfo
-
- By Matthew Hawn
- Use however you want. I can't stop you.
+/* 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
+
+ Use however you want.
+ Written by: Daniel Forchheimer (upiom)
+
*/
-
+#define VERSIONSTR "1"
#include <stdio.h>
#include <X11/Xlib.h>
#include <X11/Xatom.h>
#include "dsimple.h"
#include <stdlib.h>
+#include <getopt.h>
Window target_win;
@@ -21,7 +24,21 @@ Window target_win;
void usage()
{
- fprintf(stderr, "Bad arguments\n");
+ 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,
+ " -v, --version print version number\n");
+
+ exit(1);
}
#define OPAQUE 0xffffffff
@@ -33,53 +50,97 @@ 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
+ int flag_toggle=0;
+ int o;
+
+ int options_index=0;
+ static struct option long_options[] = {
+ {"toggle",0,NULL,'t'},
+ {"help",0,NULL,'h'},
+ {"point",0,NULL,'p'},
+ {"click",0,NULL,'c'},
+ {"version",0,NULL,'v'},
+ {0,0,0,0}
+ };
/* wonderful utility */
Setup_Display_And_Screen(&argc, argv);
- if (argv[1])
+ while ((o = getopt_long(argc, argv, "thpcv",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 'v':
+ fprintf(stderr,"version: %s\n",VERSIONSTR);
+ exit(1);
+ break;
+ default:
+ usage();
+ }
+ }
+
+ if(optind<argc)
{
- printf ("got arg %s\n", argv[1]);
- d = atof (argv[1]);
- printf ("d is %g\n", d);
+ d = atof (argv[optind]);
gotd = 1;
}
-
- /* grab mouse and return window that is next clicked */
- target_win = Select_Window(dpy);
-
+
+ if(select_method==1) {
+ /* don't wait for click */
+ target_win = Get_Window_Under_Cursor(dpy);
+ } else {
+ /* grab mouse and return window that is next clicked */
+ target_win = Select_Window(dpy);
+ }
+
unsigned char *data;
Atom actual;
int format;
unsigned long n, left;
+
if (gotd)
opacity = (unsigned int) (d * OPAQUE);
- else
- {
- /* get property */
- XGetWindowProperty(dpy, target_win, XInternAtom(dpy, OPACITY, False),
- 0L, 1L, False, XA_CARDINAL, &actual, &format, &n, &left,
- (unsigned char **) &data);
+ else
+ opacity = 0xc0000000;
+
+ /* 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 (&opacity, data, sizeof (unsigned int));
- XFree(( void *) data );
- printf("Found property: %g\n", (double) opacity / OPAQUE);
- }
- else
- opacity = OPAQUE;
+ if (data != None)
+ {
+ memcpy (&current_opacity, data, sizeof (unsigned int));
+ XFree(( void *) data );
+ // printf("Found property: %g\n", (double) opacity / OPAQUE);
+ }
+ else
+ current_opacity = OPAQUE;
+
+ /* for user-compability with transset */
+ if(!gotd) flag_toggle=1;
- /* toggle */
- if (opacity != OPAQUE)
+ /* toggle */
+ if(flag_toggle)
+ if (current_opacity != OPAQUE)
opacity = OPAQUE;
- else
- opacity = 0xc0000000;
- }
- printf ("opacity 0x%x\n", opacity);
+ // printf ("opacity 0x%x\n", opacity);
if (opacity == OPAQUE)
XDeleteProperty (dpy, target_win, XInternAtom(dpy, OPACITY, False));
/* set it */