This repository has been archived by the owner on Oct 27, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
FullScreenShell.c
392 lines (352 loc) · 10.7 KB
/
FullScreenShell.c
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
383
384
385
386
387
388
389
390
/*
* FullScreenShell
* $Id: FullScreenShell.c,v 1.2 2001/06/27 20:37:33 go Exp $
*/
#include <stdio.h>
#include "FullScreenShellP.h"
/* resources */
#define Offset(x) (XtOffsetOf(FullScreenShellRec, fullscreen.x))
static XtResource resources[] = {
{XtNscreenMode, XtCScreenMode, XtRBool, sizeof(Bool),
Offset(screen_mode), XtRImmediate, (XtPointer)False},
};
#undef Offset
/* actions */
static void ScreenMode(Widget w, XEvent *e, String *p, Cardinal *n);
static void WindowMode(Widget w, XEvent *e, String *p, Cardinal *n);
static void ScreenWindow(Widget w, XEvent *e, String *p, Cardinal *n);
static void Enter(Widget w, XEvent *e, String *p, Cardinal *n);
static void Map(Widget w, XEvent *e, String *p, Cardinal *n);
static XtActionsRec actions[] = {
{"screen", ScreenMode},
{"window", WindowMode},
{"scrwin", ScreenWindow},
{"enter", Enter},
{"map", Map},
};
/* translations */
static char translations[] =
"Meta<Key>Return: scrwin()\n"
"<Enter>: enter()\n"
"<Map>: map()";
/* class methods */
static void Initialize(Widget, Widget, ArgList args, Cardinal * num);
static void Destroy(Widget);
static void Realize(Widget, XtValueMask *, XSetWindowAttributes *);
static void Resize(Widget widget);
static CompositeClassExtensionRec fullScreenCompositeClassExtension = {
/* next_extension */ NULL,
/* record_type */ NULLQUARK,
/* version */ XtCompositeExtensionVersion,
/* record_size */ sizeof(CompositeClassExtensionRec),
/* accepts_objects */ TRUE,
/* allows_change_managed_set */ FALSE
};
#define SUPERCLASS ((WidgetClass)&sessionShellClassRec)
FullScreenShellClassRec fullScreenShellClassRec = {
{
/* superclass */ SUPERCLASS,
/* class_name */ "FullScreenShell",
/* size */ sizeof(FullScreenShellRec),
/* Class Initializer */ NULL,
/* class_part_initialize*/ NULL,
/* Class init'ed ? */ FALSE,
/* initialize */ Initialize,
/* initialize_notify */ NULL,
/* realize */ Realize,
/* actions */ actions,
/* num_actions */ XtNumber(actions),
/* resources */ resources,
/* resource_count */ XtNumber(resources),
/* xrm_class */ NULLQUARK,
/* compress_motion */ FALSE,
/* compress_exposure */ TRUE,
/* compress_enterleave*/ FALSE,
/* visible_interest */ FALSE,
/* destroy */ Destroy,
/* resize */ Resize,
/* expose */ NULL,
/* set_values */ NULL,
/* set_values_hook */ NULL,
/* set_values_almost */ XtInheritSetValuesAlmost,
/* get_values_hook */ NULL,
/* accept_focus */ NULL,
/* intrinsics version */ XtVersion,
/* callback offsets */ NULL,
/* tm_table */ translations,
/* query_geometry */ NULL,
/* display_accelerator*/ NULL,
/* extension */ NULL
},{
/* geometry_manager */ XtInheritGeometryManager,
/* change_managed */ XtInheritChangeManaged,
/* insert_child */ XtInheritInsertChild,
/* delete_child */ XtInheritDeleteChild,
/* extension */ (XtPointer)&fullScreenCompositeClassExtension
},{
/* extension */ NULL
},{
/* extension */ NULL
},{
/* extension */ NULL
},{
/* extension */ NULL
},{
/* extension */ NULL
},{
/* extension */ NULL
},{
/* extension */ NULL
}
};
WidgetClass fullScreenShellWidgetClass = (WidgetClass)(&fullScreenShellClassRec);
/* --------------------------------------------------------------------------
* private functions
*/
static XF86VidModeModeInfo *
checkModeLinesRes(XF86VidModeModeInfo **modeinfos, int count, int w, int h)
{
int i;
for (i=0;i<count;i++) {
if (modeinfos[i]->hdisplay == w && modeinfos[i]->vdisplay == h)
return modeinfos[i];
}
return NULL;
}
/**
* 全画面モードに遷移
*/
static void
_ToScreenMode(FullScreenShellWidget fssw)
{
Display *dpy = XtDisplay((Widget)fssw);
int screen_no = XScreenNumberOfScreen(XtScreen((Widget)fssw));
XF86VidModeModeInfo *sel;
if ((sel = checkModeLinesRes(FSSW.modeinfos, FSSW.vid_count, 640, 480)) == NULL &&
(sel = checkModeLinesRes(FSSW.modeinfos, FSSW.vid_count, 800, 600)) == NULL) {
fprintf(stderr, "warning: Not found good mode...");
FSSW.enable_screen_mode = False;
} else if (!XF86VidModeSwitchToMode(dpy, screen_no, sel)) {
fprintf(stderr, "warning: Can't set modeline\n");
FSSW.enable_screen_mode = False;
} else {
XF86VidModeSetViewPort(dpy, screen_no, 0, 0);
XWarpPointer(dpy, None, RootWindowOfScreen(XtScreen((Widget)fssw)),
0, 0, 0, 0, 0, 0);
XSync(dpy, False);
XtVaSetValues((Widget)fssw, XtNoverrideRedirect, True, NULL);
FSSW.getsize = False;
XtConfigureWidget((Widget)fssw, 0, 0, sel->hdisplay, sel->vdisplay, 0);
FSSW.screen_mode = True;
}
}
/* --------------------------------------------------------------------------
* Actions
*/
static void
ToWindowMode(FullScreenShellWidget fssw)
{
if (FSSW.enable_screen_mode) {
if (FSSW.screen_mode) {
XtUnmapWidget((Widget)fssw);
XtFullScreenShellWidgetRestoreMode(fssw);
FSSW.getsize = False;
XtVaSetValues((Widget)fssw, XtNoverrideRedirect, False, NULL);
XtResizeWidget((Widget)fssw, FSSW.width, FSSW.height, 0);
FSSW.screen_mode = False;
XtMapWidget((Widget)fssw);
}
}
}
static void
ToScreenMode(FullScreenShellWidget fssw)
{
if (FSSW.enable_screen_mode) {
if (!FSSW.screen_mode) {
XtUnmapWidget((Widget)fssw);
_ToScreenMode(fssw);
XtMapWidget((Widget)fssw);
XGrabPointer(XtDisplay((Widget)fssw),
XtWindow((Widget)fssw), True, 0,
GrabModeAsync, GrabModeAsync,
XtWindow((Widget)fssw), None, CurrentTime);
}
}
}
/**
* 全画面モードへ切り替え
*/
static void ScreenMode(Widget w, XEvent *e, String *p, Cardinal *n)
{
ToScreenMode((FullScreenShellWidget)w);
}
/**
* ウィンドウモードへ切り替え
*/
static void
WindowMode(Widget w, XEvent *e, String *p, Cardinal *n)
{
ToWindowMode((FullScreenShellWidget)w);
}
/**
* 全画面モードとウィンドウモードの切り替え
*/
static void
ScreenWindow(Widget w, XEvent *e, String *p, Cardinal *n)
{
FullScreenShellWidget fssw = (FullScreenShellWidget)w;
if (FSSW.screen_mode) {
ToWindowMode(fssw);
} else {
ToScreenMode(fssw);
}
}
/**
* スクリーンモードの場合は入力フォーカスを取得する
*/
static void
Enter(Widget w, XEvent *e, String *p, Cardinal *n)
{
FullScreenShellWidget fssw = (FullScreenShellWidget)w;
if (FSSW.screen_mode)
XSetInputFocus(XtDisplay(w), XtWindow(w), RevertToNone, CurrentTime);
}
/**
* スクリーンモードの場合はポインタ入力を取得する
*/
static void
Map(Widget w, XEvent *e, String *p, Cardinal *n)
{
FullScreenShellWidget fssw = (FullScreenShellWidget)w;
if (FSSW.screen_mode)
XGrabPointer(XtDisplay(w),
XtWindow(w), True, 0,
GrabModeAsync, GrabModeAsync,
XtWindow(w), None, CurrentTime);
FSSW.getsize = True;
}
/* -------------------------------------------------------------------
* Class Mehotds
*/
static void
Initialize(Widget req, Widget new, ArgList args, Cardinal * num)
{
FullScreenShellWidget fssw = (FullScreenShellWidget)new;
int major, minor;
int eventBase, errorBase;
Display *dpy = XtDisplay((Widget)fssw);
/* スクリーンモードの有効/無効チェック */
if (!XF86VidModeQueryVersion(dpy, &major, &minor)) {
fprintf(stderr, "Can't query video extension version\n");
FSSW.enable_screen_mode = False;
FSSW.screen_mode = False;
} else if (!XF86VidModeQueryExtension(dpy, &eventBase, &errorBase)) {
fprintf(stderr, "Can't query video extension information\n");
FSSW.enable_screen_mode = False;
FSSW.screen_mode = False;
} else if (major < MINMAJOR ||
(major == MINMAJOR && minor < MINMINOR)) {
fprintf(stderr, "Old XFree86-VidModeExtension version(%d.%d)\n", major, minor);
fprintf(stderr, "Required version %d.%d\n", MINMAJOR, MINMINOR);
FSSW.enable_screen_mode = False;
FSSW.screen_mode = False;
} else {
XF86VidModeModeInfo *sel;
if (!XF86VidModeGetAllModeLines(dpy,
XScreenNumberOfScreen(XtScreen(new)),
&FSSW.vid_count, &FSSW.modeinfos)) {
fprintf(stderr, "Can't get modeinfos\n");
FSSW.enable_screen_mode = False;
} else if ((sel = checkModeLinesRes(FSSW.modeinfos, FSSW.vid_count, 640, 480)) == NULL &&
(sel = checkModeLinesRes(FSSW.modeinfos, FSSW.vid_count, 800, 600)) == NULL) {
fprintf(stderr, "Not found good mode...");
FSSW.enable_screen_mode = False;
FSSW.screen_mode = False;
} else {
FSSW.enable_screen_mode = True;
}
}
FSSW.getsize = True;
}
static void
Destroy(Widget w)
{
FullScreenShellWidget fssw = (FullScreenShellWidget)w;
XtFullScreenShellWidgetRestoreMode(fssw);
}
static void
Realize(Widget w, XtValueMask *mask, XSetWindowAttributes *attr)
{
FullScreenShellWidget fssw = (FullScreenShellWidget)w;
SUPERCLASS->core_class.realize(w, mask, attr);
if (FSSW.enable_screen_mode && FSSW.screen_mode) {
/* いったんフラグを消去… */
FSSW.screen_mode = False;
_ToScreenMode(fssw);
}
}
static void
Resize(Widget widget)
{
FullScreenShellWidget fssw = (FullScreenShellWidget)widget;
if (SUPERCLASS->core_class.resize)
SUPERCLASS->core_class.resize(widget);
// サイズを記録
if (FSSW.getsize) {
FSSW.width = COREWIDTH;
FSSW.height = COREHEIGHT;
}
}
/* -------------------------------------------------------------------
* Public Functions
*/
Bool
XtFullScreenShellWidgetEnableScreenMode(FullScreenShellWidget fssw)
{
return FSSW.enable_screen_mode;
}
Bool
XtFullScreenShellWidgetScreenMode(FullScreenShellWidget fssw)
{
return FSSW.screen_mode;
}
void
XtFullScreenShellWidgetSetBestSize(FullScreenShellWidget fssw,
Dimension width, Dimension height)
{
FSSW.width = width;
FSSW.height = height;
}
/**
* 画面を最初の状態に戻す
*/
void
XtFullScreenShellWidgetRestoreMode(FullScreenShellWidget fssw)
{
if (FSSW.screen_mode) {
XF86VidModeSwitchToMode(XtDisplay((Widget)fssw),
XScreenNumberOfScreen(XtScreen((Widget)fssw)),
FSSW.modeinfos[0]);
XSync(XtDisplay((Widget)fssw), False);
FSSW.screen_mode = False;
}
}
void
XtFullScreenShellWidgetToScreenMode(FullScreenShellWidget fssw)
{
ToScreenMode(fssw);
}
void
XtFullScreenShellWidgetToWindowMode(FullScreenShellWidget fssw)
{
ToWindowMode(fssw);
}
void
XtFullScreenShellWidgetScreenWindow(FullScreenShellWidget fssw)
{
if (FSSW.screen_mode) {
ToWindowMode(fssw);
} else {
ToScreenMode(fssw);
}
}