1 /******************************************************************************
2 * recordMyDesktop *
3 *******************************************************************************
4 * *
5 * Copyright (C) 2006,2007,2008 John Varouhakis *
6 * *
7 * *
8 * This program is free software; you can redistribute it and/or modify *
9 * it under the terms of the GNU General Public License as published by *
10 * the Free Software Foundation; either version 2 of the License, or *
11 * (at your option) any later version. *
12 * *
13 * This program is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU General Public License *
19 * along with this program; if not, write to the Free Software *
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
21 * *
22 * *
23 * *
24 * For further information contact me at johnvarouhakis@gmail.com *
25 ******************************************************************************/
26
27 #include "config.h"
28 #include "rmd_frame.h"
29
30 #include <X11/Xlib.h>
31 #include <X11/extensions/shape.h>
32
33 #include <stdio.h>
34 #include <stdlib.h>
35
36
37 #define BORDER_WIDTH 6
38 #define OUTLINE_WIDTH 1
39
40
rmdDrawFrame(Display * dpy,int screen,Window win,int width,int height)41 void rmdDrawFrame(Display *dpy,
42 int screen,
43 Window win,
44 int width,
45 int height){
46
47 GC gc;
48 XGCValues gcv;
49 XColor white, white_e,
50 black, black_e ;
51 unsigned long gcmask=GCForeground;
52
53 XAllocNamedColor(dpy,DefaultColormap(dpy, screen),"white", &white, &white_e);
54 XAllocNamedColor(dpy,DefaultColormap(dpy, screen),"black", &black, &black_e);
55
56 gcv.foreground = black.pixel;
57 gc = XCreateGC(dpy,win, gcmask,&gcv);
58 XFillRectangle(dpy,
59 win,
60 gc,
61 OUTLINE_WIDTH,
62 OUTLINE_WIDTH,
63 width+(BORDER_WIDTH-OUTLINE_WIDTH)*2,
64 height+(BORDER_WIDTH-OUTLINE_WIDTH)*2);
65 gcv.foreground = white.pixel;
66 XChangeGC(dpy,gc,gcmask,&gcv);
67 XFillRectangle(dpy,
68 win,
69 gc,
70 BORDER_WIDTH-OUTLINE_WIDTH,
71 BORDER_WIDTH-OUTLINE_WIDTH,
72 width+OUTLINE_WIDTH*2,
73 height+OUTLINE_WIDTH*2);
74
75 XFreeGC(dpy, gc);
76
77 }
78
79
rmdMoveFrame(Display * dpy,Window win,int x,int y)80 void rmdMoveFrame(Display *dpy,
81 Window win,
82 int x,
83 int y){
84
85 XMoveWindow(dpy,
86 win,
87 x-BORDER_WIDTH,
88 y-BORDER_WIDTH);
89
90 // XSync(pdata->dpy,False);
91
92 }
93
rmdFrameInit(Display * dpy,int screen,Window root,int x,int y,int width,int height)94 Window rmdFrameInit(Display *dpy,
95 int screen,
96 Window root,
97 int x,
98 int y,
99 int width,
100 int height){
101
102 XSetWindowAttributes attribs;
103 XColor white, white_e;
104 Window win;
105 unsigned long valuemask=CWBackPixmap|CWBackPixel|
106 CWSaveUnder|CWOverrideRedirect|CWColormap;
107
108 XAllocNamedColor(dpy,DefaultColormap(dpy, screen),"white", &white, &white_e);
109
110 attribs.background_pixmap=None;
111 attribs.background_pixel=white.pixel;
112 attribs.save_under=True;
113 attribs.override_redirect=True;
114 attribs.colormap=DefaultColormap(dpy,screen);
115
116 win = XCreateWindow(dpy,
117 root,
118 x-BORDER_WIDTH,
119 y-BORDER_WIDTH,
120 width+BORDER_WIDTH*2,
121 height+BORDER_WIDTH*2,
122 0,
123 CopyFromParent,
124 InputOutput,
125 CopyFromParent,
126 valuemask,
127 &attribs);
128
129
130 XRectangle rect;
131 rect.x=rect.y=BORDER_WIDTH;
132 rect.width=width;
133 rect.height=height;
134
135 XShapeCombineRectangles(dpy,
136 win,
137 ShapeBounding,
138 0,
139 0,
140 &rect,
141 1,
142 ShapeSubtract,
143 0);
144
145 XMapWindow(dpy, win);
146
147 rmdDrawFrame(dpy,screen,win,width,height);
148
149 return win;
150 }
151
152
153
154
155
156
157
158
159