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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
|
program x11wininfo;
{$mode objfpc}{$H+}
uses
{$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads,
{$ENDIF}{$ENDIF}
Classes, SysUtils, fpg_base, fpg_main, fpg_form, fpg_label, fpg_panel,
fpg_button, fpg_listbox, fpg_impl, fpg_tab, fpg_edit, fpg_x11,
xlib, x;
type
TMainForm = class(TfpgForm)
private
{@VFD_HEAD_BEGIN: MainForm}
Button1: TfpgButton;
PageControl1: TfpgPageControl;
TabSheet1: TfpgTabSheet;
Edit1: TfpgEdit;
Edit2: TfpgEdit;
Label1: TfpgLabel;
lblPos: TfpgLabel;
Label3: TfpgLabel;
lblSize: TfpgLabel;
Label2: TfpgLabel;
lblHandle: TfpgLabel;
Bevel1: TfpgBevel;
Label4: TfpgLabel;
{@VFD_HEAD_END: MainForm}
FTimer: TfpgTimer;
FOutlineGC: TfpgGContext;
FOutlineDrawn: Boolean;
newrect: TfpgRect;
lastRect: TfpgRect;
last_child: TfpgWinHandle;
procedure btnWinInfoClicked(Sender: TObject);
procedure TimerFired(Sender: TObject);
procedure InitOutline;
procedure DrawOutline;
procedure ClearOutine;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure AfterCreate; override;
end;
{ TMainForm }
procedure TMainForm.btnWinInfoClicked(Sender: TObject);
begin
FTimer.Enabled := not FTimer.Enabled;
ClearOutine;
end;
procedure TMainForm.TimerFired(Sender: TObject);
type
AChildren = array[0..0] of TfpgWinHandle;
PChildren = ^AChildren;
var
rootw: TfpgWinHandle;
parentw: TfpgWinHandle;
children: PChildren;
cnum: longword;
ret_root: TfpgWinHandle;
ret_child: TfpgWinHandle;
root_x, root_y: integer;
child_x, child_y: integer;
mask: longword;
x: integer;
winrect: TfpgRect;
wa: TXWindowAttributes;
begin
rootw := DefaultRootWindow(fpgApplication.Display);
x := 1;
XQueryPointer(fpgApplication.Display, rootw, @ret_root, @ret_child,
@root_x, @root_y, @child_x, @child_y, @mask);
while ret_child <> 0 do
begin
last_child := ret_child;
if XQueryPointer(fpgApplication.Display, ret_child, @ret_root, @ret_child,
@root_x, @root_y, @child_x, @child_y, @mask) then
begin
// writeln('X=', x);
Inc(x);
// writeln('Button.WinHandle: ', IntToHex(Button1.WinHandle, 6));
// writeln('WinHandle under pointer: ', IntToHex(ret_child, 6));
end;
end;
XGetWindowAttributes(fpgApplication.Display, last_child, @wa);
winrect.SetRect(wa.x, wa.y, wa.width, wa.height);
// writeln('----start----');
// PrintRect(winrect);
XTranslateCoordinates(fpgApplication.Display,
last_child, DefaultRootWindow(fpgApplication.Display),
wa.X, wa.Y, @root_x, @root_y, @ret_child);
newrect.SetRect(root_x-wa.X, root_y-wa.Y, wa.width, wa.height);
// PrintRect(newrect);
// writeln('----done----');
ClearOutine;
DrawOutline;
exit; //==>
children := nil;
if XQueryTree(
fpgApplication.Display,
DefaultRootWindow(fpgApplication.Display),
@rootw, @parentw, @children, @cnum) <> 0 then
begin
end;
if children <> nil then
XFree(children);
end;
procedure TMainForm.InitOutline;
var
gcValues: TXGCValues;
begin
gcValues._function := GXxor; //GXinvert;
gcValues.subwindow_mode := IncludeInferiors;
gcValues.line_width := 2;
FOutlineGC := XCreateGC(
fpgApplication.Display,
DefaultRootWindow(fpgApplication.Display),
GCFunction or GCSubwindowMode or GCLineWidth, @gcValues);
XSetForeGround(fpgApplication.display, FOutlineGC, fpgColorToX(clRed));
FOutlineDrawn := False;
end;
procedure TMainForm.DrawOutline;
begin
if not FOutlineDrawn then
begin
XSync(fpgApplication.Display, False);
XDrawRectangle(
fpgApplication.Display,
DefaultRootWindow(fpgApplication.Display),
FOutlineGC,
newrect.Left, newrect.Top, newrect.Width, newrect.Height);
lastrect := newrect;
FOutlineDrawn := True;
lblPos.Text := Format('(%d,%d)', [newrect.Left, newRect.Top]);
lblSize.Text := Format('(%d,%d)', [newrect.Width, newRect.Height]);
lblHandle.Text := IntToHex(last_child, 6);
end;
end;
procedure TMainForm.ClearOutine;
begin
if FOutlineDrawn then
begin
XDrawRectangle(
fpgApplication.Display,
DefaultRootWindow(fpgApplication.Display),
FOutlineGC,
lastrect.Left, lastrect.Top, lastrect.Width, lastrect.Height);
FOutlineDrawn := False;
XSync(fpgApplication.Display, False);
end;
end;
constructor TMainForm.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FTimer := TfpgTimer.Create(80);
FTimer.OnTimer := @TimerFired;
InitOutline;
end;
destructor TMainForm.Destroy;
begin
ClearOutine;
XFreeGC(fpgApplication.Display, FOutlineGC);
inherited Destroy;
end;
procedure TMainForm.AfterCreate;
begin
{@VFD_BODY_BEGIN: MainForm}
Name := 'MainForm';
SetPosition(334, 226, 300, 309);
WindowTitle := 'fpGUI Window Information';
WindowPosition := wpUser;
Button1 := TfpgButton.Create(self);
with Button1 do
begin
Name := 'Button1';
SetPosition(208, 8, 80, 24);
Text := 'wininfo';
AllowAllUp := False;
Embedded := False;
Flat := False;
FontDesc := '#Label1';
GroupIndex := 0;
Hint := '';
ImageLayout := ilImageLeft;
ImageMargin := 3;
ImageName := '';
ImageSpacing := -1;
ParentShowHint := True;
ShowImage := True;
TabOrder := 0;
OnClick :=@btnWinInfoClicked;
end;
PageControl1 := TfpgPageControl.Create(self);
with PageControl1 do
begin
Name := 'PageControl1';
SetPosition(16, 172, 274, 116);
ActivePageIndex := 0;
ParentShowHint := True;
TabOrder := 3;
end;
TabSheet1 := TfpgTabSheet.Create(PageControl1);
with TabSheet1 do
begin
Name := 'TabSheet1';
SetPosition(3, 24, 268, 89);
Text := 'TabSheet1';
end;
Edit1 := TfpgEdit.Create(TabSheet1);
with Edit1 do
begin
Name := 'Edit1';
SetPosition(140, 12, 120, 22);
TabOrder := 0;
Text := '';
FontDesc := '#Edit1';
ParentShowHint := True;
end;
Edit2 := TfpgEdit.Create(TabSheet1);
with Edit2 do
begin
Name := 'Edit2';
SetPosition(24, 52, 22, 22);
TabOrder := 1;
Text := '';
FontDesc := '#Edit1';
ParentShowHint := True;
end;
Label1 := TfpgLabel.Create(self);
with Label1 do
begin
Name := 'Label1';
SetPosition(12, 44, 68, 16);
Alignment := taLeftJustify;
FontDesc := '#Label2';
Hint := '';
Layout := tlTop;
ParentShowHint := True;
Text := 'Left, Top:';
WrapText := False;
end;
lblPos := TfpgLabel.Create(self);
with lblPos do
begin
Name := 'lblPos';
SetPosition(120, 44, 80, 16);
Alignment := taLeftJustify;
FontDesc := '#Label1';
Hint := '';
Layout := tlTop;
ParentShowHint := True;
Text := '-';
WrapText := False;
end;
Label3 := TfpgLabel.Create(self);
with Label3 do
begin
Name := 'Label3';
SetPosition(12, 68, 100, 16);
Alignment := taLeftJustify;
FontDesc := '#Label2';
Hint := '';
Layout := tlTop;
ParentShowHint := True;
Text := 'Width, Height:';
WrapText := False;
end;
lblSize := TfpgLabel.Create(self);
with lblSize do
begin
Name := 'lblSize';
SetPosition(120, 68, 80, 16);
Alignment := taLeftJustify;
FontDesc := '#Label1';
Hint := '';
Layout := tlTop;
ParentShowHint := True;
Text := '-';
WrapText := False;
end;
Label2 := TfpgLabel.Create(self);
with Label2 do
begin
Name := 'Label2';
SetPosition(12, 92, 80, 16);
Alignment := taLeftJustify;
FontDesc := '#Label2';
Hint := '';
Layout := tlTop;
ParentShowHint := True;
Text := 'Handle:';
WrapText := False;
end;
lblHandle := TfpgLabel.Create(self);
with lblHandle do
begin
Name := 'lblHandle';
SetPosition(120, 92, 80, 16);
Alignment := taLeftJustify;
FontDesc := '#Label1';
Hint := '';
Layout := tlTop;
ParentShowHint := True;
Text := '-';
WrapText := False;
end;
Bevel1 := TfpgBevel.Create(self);
with Bevel1 do
begin
Name := 'Bevel1';
SetPosition(24, 132, 248, 28);
BorderStyle := bsSingle;
ParentShowHint := True;
Style := bsRaised;
end;
Label4 := TfpgLabel.Create(self);
with Label4 do
begin
Name := 'Label4';
SetPosition(42, 137, 223, 16);
Alignment := taLeftJustify;
FontDesc := '#Label2';
Hint := '';
Layout := tlTop;
ParentShowHint := True;
Text := '===== Below is a test area =====';
WrapText := False;
end;
{@VFD_BODY_END: MainForm}
end;
procedure MainProc;
var
frm: TMainForm;
begin
fpgApplication.Initialize;
frm := TMainForm.Create(nil);
try
frm.Show;
fpgApplication.Run;
finally
frm.Free;
end;
end;
begin
MainProc;
end.
|