commit 164adbf3a0299bddee121732033d294a83b17e4d
parent f90b121e61f1e48890e29742122033e5107ddaf0
Author: muquit <muquit@gmail.com>
Date: Wed, 11 Apr 2018 20:48:42 -0400
Update
Diffstat:
M | ChangeLog.md | | | 24 | +++++++++++------------- |
M | README.md | | | 77 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------- |
M | grabc.c | | | 35 | ++++++++++++++++++++++++++--------- |
3 files changed, 106 insertions(+), 30 deletions(-)
diff --git a/ChangeLog.md b/ChangeLog.md
@@ -1,17 +1,15 @@
-v1.0.2
-======
- * Was not working properly on Ubuntu Terminal.
- It was using default Colormap. Do not use default colormap,
- rather get it from window attributes.
-
- * If could not get XImage from target window, it is probably root window,
+# v1.0.2
+ * Was not working properly on Ubuntu Terminal. It was using default Colormap. Do not use default colormap, rather get it from window attributes.
+ * If could not get XImage from target window, it is probably root window,
so try to grab it from there.
+* Added some options
+* Color can be grabbed from a specific location
+
+* Change Copyright to MIT from GNU GPL
- * Added options
+(Apr-10-2018)
- (Apr-10-2018)
+# v1.0.1
+* first cut
-v1.0.1
-======
- - first cut
- (march-16-1997)
+(march-16-1997)
diff --git a/README.md b/README.md
@@ -1,3 +1,4 @@
+# grabc
A command line tool for X Window System to identify the color string in hex by clicking on a pixel.
When this program is run, the mouse pointer is grabbed and changed to
@@ -9,15 +10,75 @@ A command line tool for X Window System to identify the color string in hex by c
name of the color is. It's silly to use a image processing software
to find it out.
-To compile, at the shell prompt, type:
+# Synopsis
+
+```
+grabc Version: 1.0.2
+A program to identify a pixel color of an X Window
+by muquit@muquit.com https://www.muquit.com/
+
+Usage: grabc [options]
+Where the options are:
+ -v - show version info
+ -h - show this usage
+ -hex - print pixel value as Hex on stdout
+ -rgb - print pixel value as RGB on stderr
+ -W - print the Window id at mouse click
+ -w id - window id in hex, use before -l
+ -l +x+y - pixel co-ordinate. requires window id
+ -d - show debug messages
+ -a - Print all 16 bits of color. Default is high order 8 bits
+Example:
+* Print pixel color in hex on stdout and rgb on stderr:
+ Default behavior
+ $ grabc
+
+* Show usage:
+ $ grabc -h
+
+* Print Window Id (Note the upper case W):
+ $ grabc -W
+#0x13234
+
+* Print pixel color of Window with id 0x13234 at location 10,20
+ $ grabc -w 0x13234 -l +10+20
+```
+
+# How to compile
+Older version of this program is available on Ubuntu. However, if you need to get the latest version, you have to compile it yourself.
+
+* You will need ```libx11-dev``` package if you are on Ubuntu.
+```
+ sudo apt-get -y install libx11-dev
+```
+
+
+* To compile, at the shell prompt, type:
+```
make
-
---
+```
+
+# Example
+
+# ChangeLog
+
+# v1.0.2
+ * Was not working properly on Ubuntu Terminal. It was using default Colormap. Do not use default colormap, rather get it from window attributes.
+ * If could not get XImage from target window, it is probably root window,
+ so try to grab it from there.
+* Added some options
+* Color can be grabbed from a specific location
+
+* Change Copyright to MIT from GNU GPL
+
+(Apr-10-2018)
+
+# v1.0.1
+* first cut
+
+(march-16-1997)
- v1.0.1
- March 16, 1997
---
+# License
- v1.0.2
- Updated: Apr-10-2018
+MIT
diff --git a/grabc.c b/grabc.c
@@ -56,7 +56,7 @@
#define VERSION_S "1.0.2"
static int g_debug = False;
-static int g_print_in_hex = False;
+static int g_print_in_hex = True;
static int g_print_in_rgb = False;
static int g_print_all_16_bits = False;
static Window g_window_id = (Window) NULL;
@@ -329,8 +329,6 @@ static Window findSubWindow(Display *display,Window top_window,
(*x)=newx;
(*y)=newy;
- log_debug("Window id: %lx",window);
-
return (window);
}
@@ -361,7 +359,6 @@ static Window get_window_color(Display *display,XColor *color)
status;
root_window=XRootWindow(display,XDefaultScreen(display));
- log_debug("Root window: 0x%08lx",root_window);
target_window=select_window(display,&x,&y);
log_debug("Selected Window id: %lx",target_window);
@@ -490,7 +487,7 @@ int main(int argc,char **argv)
{
if (strncmp("hex",option+1,3) == 0)
{
-
+ g_print_in_hex = True;
}
else
{
@@ -500,6 +497,15 @@ int main(int argc,char **argv)
break;
}
+ case 'r':
+ {
+ if (strncmp("rgb",option+1,3) == 0)
+ {
+ g_print_in_rgb = True;
+ }
+ break;
+ }
+
case 'w':
{
if (*option == '-')
@@ -617,6 +623,14 @@ int main(int argc,char **argv)
(unsigned int) color.green,
(unsigned int) color.blue);
(void) fflush(stdout);
+ if (g_print_in_rgb)
+ {
+ (void) fprintf(stderr,"%d,%d,%d\n",
+ (unsigned int)color.red,
+ (unsigned int) color.green,
+ (unsigned int) color.blue);
+ }
+
}
else
{
@@ -625,11 +639,14 @@ int main(int argc,char **argv)
b=(color.blue >> 8);
(void) fprintf (stdout,"#%02x%02x%02x\n",r,g,b);
(void) fflush(stdout);
+ /*
+ ** write the values in decimal on stderr
+ */
+ if (g_print_in_rgb)
+ {
+ (void) fprintf(stderr,"%d,%d,%d\n",r,g,b);
+ }
}
- /*
- ** write the values in decimal on stderr
- */
- (void) fprintf(stderr,"%d,%d,%d\n",r,g,b);
}
else
{