File: Grab.c

package info (click to toggle)
xtv 1.1-16
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 152 kB
  • sloc: ansic: 614; makefile: 193
file content (195 lines) | stat: -rw-r--r-- 4,627 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
/*
** Grab.c for XmtdsGrab widget in .
**
** Made by MaxTheDogSays (dubray_f@epita.fr && rancur_v@epita.fr
** Login   <vr@epita.fr>
**
** Started on  Mon May 16 22:24:08 1994 vr
** Last update Tue Apr  4 02:31:06 1995 mtds
*/

#include <X11/IntrinsicP.h>
#include <X11/StringDefs.h>
#include <stdio.h>
#include <stdlib.h>
#include "XmtdsI.h"
#include "GrabP.h"

static void			Initialize();
static void			SetValues();
static void			Redisplay();
static void			Destroy();

static void			timer();

static void			copy();

static XtResource	resources[] =
{
{XmtdsNdisplayName,	XmtdsCDisplayName,XtRString,	sizeof (char *),
    XtOffset(XmtdsGrabWidget,	xmtds_grab.display_name),
    XtRString,		NULL},
{XmtdsNinterval,		XmtdsCInterval,	XtRInt,		sizeof (int),
    XtOffset(XmtdsGrabWidget,	xmtds_grab.interval),
    XtRString,		"200"}
};

XmtdsGrabClassRec	xmtdsGrabClassRec = {
{
   /* core */
   (WidgetClass)&widgetClassRec,	/* superclass		*/
   "XmtdsGrab",				/* class name		*/
   sizeof(XmtdsGrabRec),		/* size			*/
   NULL,				/* class initialize	*/
   NULL,				/* class_part_init	*/
   FALSE,				/* class_inited		*/
   Initialize,				/* initialize		*/
   NULL,				/* initialize_hook	*/
   XtInheritRealize,			/* realize		*/
   NULL,				/* actions		*/
   0,					/* num_actions		*/
   resources,				/* resources		*/
   XtNumber(resources),			/* resource_count	*/
   NULLQUARK,				/* xrm_class		*/
   TRUE,				/* compress_motion	*/
   TRUE,				/* compress_exposure	*/
   TRUE,				/* compress_enterleave	*/
   FALSE,				/* visible_interest	*/
   Destroy,				/* destroy		*/
   NULL,				/* resize		*/
   Redisplay,				/* expose		*/
   NULL,				/* set_values		*/
   NULL,				/* set_values_hook	*/
   XtInheritSetValuesAlmost,		/* set_values_almost	*/
   NULL,				/* get_values_hook	*/
   NULL,				/* accept_focus		*/
   XtVersion,				/* version		*/
   NULL,				/* callback_private	*/
   NULL,				/* tm_table		*/
   XtInheritQueryGeometry,		/* query_geometry	*/
   XtInheritDisplayAccelerator,		/* display_accelerator	*/
   NULL,				/* extension		*/
},
/* xmtds_grab */
{
   0,					/* empty		*/
}
};

WidgetClass	xmtdsGrabWidgetClass = (WidgetClass)&xmtdsGrabClassRec;

static void		Initialize(request,new,args,num_args)
XmtdsGrabWidget		request;
XmtdsGrabWidget		new;
ArgList			args;
Cardinal		*num_args;
{
   XGCValues		xgcv;

   if ((NEW_GRAB.display =
	XOpenDisplay((char *)NEW_GRAB.display_name)) == NULL)
   {
      XtWarning("can't open display");
      exit(-1);
   }
   xgcv.function = GXcopy;
   NEW_GRAB.gc = XCreateGC(XtDisplay(new),
			   W_ROOT(new),
			   GCFunction,
			   &xgcv);
   NEW_GRAB.xt_interval_id =
      XtAppAddTimeOut(XtWidgetToApplicationContext((Widget)new),
		      NEW_GRAB.interval,
		      (XtTimerCallbackProc)timer,
		      (void *)new);
   NEW_CORE.width =
      DisplayWidth(NEW_GRAB.display,DefaultScreen(NEW_GRAB.display));
   NEW_CORE.height =
      DisplayHeight(NEW_GRAB.display,DefaultScreen(NEW_GRAB.display));
}

static void		SetValues(old,request,new,args,num_args)
XmtdsGrabWidget		old;
XmtdsGrabWidget		request;
XmtdsGrabWidget		new;
ArgList			args;
Cardinal		*num_args;
{
  /* TODO */
}

static void		Redisplay(w,event,region)
XmtdsGrabWidget		w;
XExposeEvent		*event;
Region			region;
{
   copy(w,event->x,event->y,event->width,event->height);
}

static void		Destroy(w)
XmtdsGrabWidget	w;
{
   XCloseDisplay(GRAB.display);
   XtRemoveTimeOut(GRAB.xt_interval_id);
}

static void			timer(w,id)
XmtdsGrabWidget			w;
XtIntervalId			*id;
{
   Dimension			width;
   Dimension			height;

#ifdef SYNC
   XSync(XtDisplay(w),FALSE);
#endif /* SYNC */
   XtVaGetValues(XtParent(w),
		 XtNwidth,	&width,
		 XtNheight,	&height,
		 NULL);
   copy(w,ABS(CORE.x),ABS(CORE.y),width,height);
   GRAB.xt_interval_id =
      XtAppAddTimeOut(XtWidgetToApplicationContext((Widget)w),
		      GRAB.interval,
		      timer,
		      (void *)w);
}

static void		copy(w,x,y,width,height)
XmtdsGrabWidget		w;
Position		x;
Position		y;
Dimension		width;
Dimension		height;
{
   XImage		*image;
   Dimension		dpy_width;
   Dimension		dpy_height;

   dpy_width = DisplayWidth(GRAB.display,DefaultScreen(GRAB.display));
   dpy_height = DisplayHeight(GRAB.display,DefaultScreen(GRAB.display));
   if ((x + width) > dpy_width)
     width = dpy_width - x;
   if ((y + height) > dpy_height)
     height = dpy_height - y;
   image =
     XGetImage(GRAB.display,
		DefaultRootWindow(GRAB.display),
		x,
		y,
		width,
		height,
		AllPlanes,
		ZPixmap);
   XPutImage(XtDisplay(w),
	     XtWindow(w),
	     GRAB.gc,
	     image,
	     0,
	     0,
	     x,
	     y,
	     width,
	     height);
   XDestroyImage(image);
}