grabc

Tool to identify pixel colors on X
git clone https://git.sinitax.com/muquit/grabc
Log | Files | Refs | README | Upstream | sfeed.txt

commit 8b62dd9931eb3d40ea5d04335f8bd9392bc36f5e
parent 5e45ad30c1e271a4fdc8f70b517784f3ed798cb4
Author: muquit <muquit@gmail.com>
Date:   Fri, 13 Apr 2018 17:05:30 -0400

Add documents

Diffstat:
MMakefile | 7+++++++
MREADME.md | 8+++++---
Agrabc.1 | 184+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mgrabc.c | 21+++++++++------------
Agrabc.pod | 46++++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 251 insertions(+), 15 deletions(-)

diff --git a/Makefile b/Makefile @@ -27,5 +27,12 @@ all: $(PROGNAME) $(PROGNAME) : $(OBJS) $(CC) $(CFLAGS) -o $(PROGNAME) $(OBJS) $(LIBS) +doc: + pod2man grabc.pod > grabc.1 + +install: + sudo cp grabc /usr/local/bin + sudo cp grabc.1 /usr/local/share/man/man1/ + clean: rm -f $(OBJS) $(PROGNAME) core diff --git a/README.md b/README.md @@ -1,5 +1,5 @@ # grabc -A command line tool to identify color a pixel on a X Window. +A command line tool to identify a pixel color on an X Window. When this program is run, the mouse pointer is grabbed and changed to a cross hair and when the mouse is clicked, the color of the clicked @@ -8,7 +8,8 @@ pixel is written to stdout in hex prefixed with # This program can be useful when you see a color and want to use the color in xterm or your window manager's border but no clue what the name of the color is. It's silly to use a image processing software -to find it out. (That's how I described it 20 years ago, so keeping it this way for historical reasons - Apr-11-2018). +to find it out. (That's how I described it 20 years ago, so keeping it +this way for historical reasons - Apr-11-2018). # Synopsis @@ -55,7 +56,8 @@ Older version of this program is available on Ubuntu. However, if you need to ge # Know Issues -* If color grabbed from root window, it might always show #000000 +* If color grabbed from root window, it might always show #000000 (Depending +on the Window Manager in user) # ChangeLog diff --git a/grabc.1 b/grabc.1 @@ -0,0 +1,184 @@ +.\" Automatically generated by Pod::Man 2.28 (Pod::Simple 3.29) +.\" +.\" Standard preamble: +.\" ======================================================================== +.de Sp \" Vertical space (when we can't use .PP) +.if t .sp .5v +.if n .sp +.. +.de Vb \" Begin verbatim text +.ft CW +.nf +.ne \\$1 +.. +.de Ve \" End verbatim text +.ft R +.fi +.. +.\" Set up some character translations and predefined strings. \*(-- will +.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left +.\" double quote, and \*(R" will give a right double quote. \*(C+ will +.\" give a nicer C++. Capital omega is used to do unbreakable dashes and +.\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, +.\" nothing in troff, for use with C<>. +.tr \(*W- +.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' +.ie n \{\ +. ds -- \(*W- +. ds PI pi +. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch +. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch +. ds L" "" +. ds R" "" +. ds C` "" +. ds C' "" +'br\} +.el\{\ +. ds -- \|\(em\| +. ds PI \(*p +. ds L" `` +. ds R" '' +. ds C` +. ds C' +'br\} +.\" +.\" Escape single quotes in literal strings from groff's Unicode transform. +.ie \n(.g .ds Aq \(aq +.el .ds Aq ' +.\" +.\" If the F register is turned on, we'll generate index entries on stderr for +.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index +.\" entries marked with X<> in POD. Of course, you'll have to process the +.\" output yourself in some meaningful fashion. +.\" +.\" Avoid warning from groff about undefined register 'F'. +.de IX +.. +.nr rF 0 +.if \n(.g .if rF .nr rF 1 +.if (\n(rF:(\n(.g==0)) \{ +. if \nF \{ +. de IX +. tm Index:\\$1\t\\n%\t"\\$2" +.. +. if !\nF==2 \{ +. nr % 0 +. nr F 2 +. \} +. \} +.\} +.rr rF +.\" +.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). +.\" Fear. Run. Save yourself. No user-serviceable parts. +. \" fudge factors for nroff and troff +.if n \{\ +. ds #H 0 +. ds #V .8m +. ds #F .3m +. ds #[ \f1 +. ds #] \fP +.\} +.if t \{\ +. ds #H ((1u-(\\\\n(.fu%2u))*.13m) +. ds #V .6m +. ds #F 0 +. ds #[ \& +. ds #] \& +.\} +. \" simple accents for nroff and troff +.if n \{\ +. ds ' \& +. ds ` \& +. ds ^ \& +. ds , \& +. ds ~ ~ +. ds / +.\} +.if t \{\ +. ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" +. ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' +. ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' +. ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' +. ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' +. ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' +.\} +. \" troff and (daisy-wheel) nroff accents +.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' +.ds 8 \h'\*(#H'\(*b\h'-\*(#H' +.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] +.ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' +.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' +.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] +.ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] +.ds ae a\h'-(\w'a'u*4/10)'e +.ds Ae A\h'-(\w'A'u*4/10)'E +. \" corrections for vroff +.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' +.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' +. \" for low resolution devices (crt and lpr) +.if \n(.H>23 .if \n(.V>19 \ +\{\ +. ds : e +. ds 8 ss +. ds o a +. ds d- d\h'-1'\(ga +. ds D- D\h'-1'\(hy +. ds th \o'bp' +. ds Th \o'LP' +. ds ae ae +. ds Ae AE +.\} +.rm #[ #] #H #V #F C +.\" ======================================================================== +.\" +.IX Title "GRABC 1" +.TH GRABC 1 "2018-04-13" "perl v5.22.1" "User Contributed Perl Documentation" +.\" For nroff, turn off justification. Always turn off hyphenation; it makes +.\" way too many mistakes in technical documents. +.if n .ad l +.nh +.SH "NAME" +grabc \- A tool to identify a pixel color of an X Window. +.SH "SYNOPSIS" +.IX Header "SYNOPSIS" +.Vb 3 +\& grabc v1.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 \-l +x+y +\& \-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: +\& $ grabc +\& * Show usage: +\& $ grabc \-h +\& * Print Window Id (Note the upper case W): +\& $ grabc \-W +\& * Print pixel color of Window iwith id 0x13234 at location 10,20 +\& $ grabc \-w 0x13234 \-l +10+20 +.Ve +.SH "DESCRIPTION" +.IX Header "DESCRIPTION" +grabc is a simple but very useful program to determine the color string in +hex (or in \s-1RGB\s0 components) by clicking on a pixel on the screen. While web +browsing, lots of time you find a nice color and wonder what color is that. +Well just use grabc! +.PP +When this program is run, the mouse pointer is grabbed and changed to a +cross hair and when the mouse is clicked, the color of the clicked pixel +is written to stdout in hex prefixed with #. +.SH "AUTHOR" +.IX Header "AUTHOR" +grabc is written by Muhammad Muquit <muquit@muquit.com>. +Homepage: <https://www.muquit.com/>. diff --git a/grabc.c b/grabc.c @@ -35,6 +35,7 @@ #include <math.h> #include <signal.h> #include <time.h> +#include <errno.h> #include <X11/Xos.h> #include <X11/Xlib.h> @@ -128,7 +129,7 @@ static void log_debug(const char *fmt,...) return; } va_start(args, fmt); - (void) fprintf(stderr,"(debug): "); + (void) fprintf(stderr,"[Debug]: "); vfprintf(stderr,fmt,args); (void) fprintf(stderr,"\n"); va_end(args); @@ -207,8 +208,6 @@ static Window select_window(Display *display,int *x,int *y) Cursor target_cursor; - static Cursor - cross_cursor=(Cursor) NULL; int status; @@ -233,7 +232,7 @@ static Window select_window(Display *display,int *x,int *y) target_window=(Window) NULL; target_cursor = get_cross_cursor(display); root_window=XRootWindow(display,XDefaultScreen(display)); - log_debug("Root window: 0x%08lx",root_window); +// log_debug("Root Window ID: 0x%08lx",root_window); status=XGrabPointer(display,root_window,False, (unsigned int) ButtonPressMask,GrabModeSync, @@ -257,7 +256,6 @@ static Window select_window(Display *display,int *x,int *y) "ERROR: Failed to get target window, getting root window!\n"); target_window=root_window; } - log_debug("Target Window id: 0x%lx", target_window); if (!g_loc_specified) { XUngrabPointer(display,CurrentTime); @@ -272,11 +270,9 @@ static Window select_window(Display *display,int *x,int *y) } /* free things we do not need, always a good practice */ - XFreeCursor(display,cross_cursor); (*x)=event.xbutton.x; (*y)=event.xbutton.y; - log_debug("x,y: +%d+%d",(*x),(*y)); return (target_window); } @@ -352,18 +348,18 @@ static Window get_window_color(Display *display,XColor *color) root_window=XRootWindow(display,XDefaultScreen(display)); target_window=select_window(display,&x,&y); - log_debug("Selected Window id: 0x%lx",target_window); + log_debug(" Root Window Id: 0x%08lx",root_window); + log_debug("Target Window Id: 0x%08lx X,Y: +%d+%d",target_window,x,y); if (target_window == (Window) NULL) return (Window) NULL; - log_debug("Getting Ximage x,y:%d,%d",x,y); ximage=XGetImage(display,target_window,x,y,1,1,AllPlanes,ZPixmap); if (ximage == (XImage *) NULL) { /* Try root window */ - log_debug("Could not get XImage from window: 0x%lx",target_window); - log_debug("Trying to get XImage from root window: 0x%lx",root_window); + log_debug("Could not get XImage from Window: 0x%08lx",target_window); + log_debug("Trying to get XImage from root window: 0x%08lx",root_window); ximage=XGetImage(display,root_window,x,y,1,1,AllPlanes,ZPixmap); if (ximage == (XImage *) NULL) { @@ -509,7 +505,6 @@ int main(int argc,char **argv) } } g_window_id = (Window) strtol(argv[i],NULL, 16); - break; } case 'W': @@ -523,6 +518,7 @@ int main(int argc,char **argv) Window window = select_window(display, &x, &y); if (window != (Window) NULL) { + log_debug("Window ID: 0x%08lx",window); (void) fprintf(stdout,"0x%lx\n",window); } return(1); @@ -614,6 +610,7 @@ int main(int argc,char **argv) r=(color.red >> 8); g=(color.green >> 8); b=(color.blue >> 8); + log_debug("Color: #%02x%02x%02x",r,g,b); (void) fprintf (stdout,"#%02x%02x%02x\n",r,g,b); (void) fflush(stdout); /* diff --git a/grabc.pod b/grabc.pod @@ -0,0 +1,46 @@ +=head1 NAME + +grabc - A tool to identify a pixel color of an X Window. + +=head1 SYNOPSIS + + grabc v1.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 -l +x+y + -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: + $ grabc + * Show usage: + $ grabc -h + * Print Window Id (Note the upper case W): + $ grabc -W + * Print pixel color of Window iwith id 0x13234 at location 10,20 + $ grabc -w 0x13234 -l +10+20 + +=head1 DESCRIPTION + +grabc is a simple but very useful program to determine the color string in +hex (or in RGB components) by clicking on a pixel on the screen. While web +browsing, lots of time you find a nice color and wonder what color is that. +Well just use grabc! + +When this program is run, the mouse pointer is grabbed and changed to a +cross hair and when the mouse is clicked, the color of the clicked pixel +is written to stdout in hex prefixed with #. + +=head1 AUTHOR + +grabc is written by Muhammad Muquit E<lt>muquit@muquit.comE<gt>. +Homepage: L<https://www.muquit.com/>.