Skip to content

Latest commit

 

History

History
397 lines (351 loc) · 10.5 KB

SDL_ph_wm.c

File metadata and controls

397 lines (351 loc) · 10.5 KB
 
Apr 26, 2001
Apr 26, 2001
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Sam Lantinga
Dec 14, 2001
Dec 14, 2001
20
slouken@libsdl.org
Apr 26, 2001
Apr 26, 2001
21
22
23
24
25
26
27
*/
#ifdef SAVE_RCSID
static char rcsid =
"@(#) $Id$";
#endif
May 10, 2001
May 10, 2001
28
29
#define DISABLE_X11
Apr 26, 2001
Apr 26, 2001
30
31
32
#include <stdlib.h>
#include <string.h>
#include <Ph.h>
May 10, 2001
May 10, 2001
33
34
35
#include <photon/PpProto.h>
#include <photon/PhWm.h>
#include <photon/wmapi.h>
Apr 26, 2001
Apr 26, 2001
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
#include "SDL_version.h"
#include "SDL_error.h"
#include "SDL_timer.h"
#include "SDL_video.h"
#include "SDL_syswm.h"
#include "SDL_events_c.h"
#include "SDL_pixels_c.h"
#include "SDL_ph_modes_c.h"
#include "SDL_ph_wm_c.h"
/* This is necessary for working properly with Enlightenment, etc. */
#define USE_ICON_WINDOW
void ph_SetIcon(_THIS, SDL_Surface *icon, Uint8 *mask)
{
#if 0 /*big*/
int ncolors;
PhImage_t *image;
PgColor_t* palette;
image = PhCreateImage( image,
icon->w,
icon->h,
Pg_IMAGE_DIRECT_888,
NULL, 0, 0 );
/* ---------------------------------------- */
SDL_Surface *sicon;
// XWMHints *wmhints;
// XImage *icon_image;
// Pixmap icon_pixmap;
// Pixmap mask_pixmap;
// GC GC;
// XGCValues GCvalues;
int i, b, dbpp;
SDL_Rect bounds;
Uint8 *LSBmask, *color_tried;
Visual *dvis;
/* Lock the event thread, in multi-threading environments */
SDL_Lock_EventThread();
/* The icon must use the default visual, depth and colormap of the
screen, so it might need a conversion */
// ? dbpp = DefaultDepth(SDL_Display, SDL_Screen);
switch(dbpp) {
case 15:
dbpp = 16; break;
case 24:
dbpp = 32; break;
}
dvis = DefaultVisual(SDL_Display, SDL_Screen);
/* The Visual struct is supposed to be opaque but we cheat a little */
sicon = SDL_CreateRGBSurface(SDL_SWSURFACE, icon->w, icon->h,
dbpp,
dvis->red_mask, dvis->green_mask,
dvis->blue_mask, 0);
if ( sicon == NULL ) {
goto done;
}
/* If we already have allocated colours from the default colormap,
copy them */
if(SDL_Visual == dvis && SDL_XColorMap == SDL_DisplayColormap
&& this->screen->format->palette && sicon->format->palette) {
memcpy(sicon->format->palette->colors,
this->screen->format->palette->colors,
this->screen->format->palette->ncolors * sizeof(SDL_Color));
}
bounds.x = 0;
bounds.y = 0;
bounds.w = icon->w;
bounds.h = icon->h;
if ( SDL_LowerBlit(icon, &bounds, sicon, &bounds) < 0 )
goto done;
/* Lock down the colors used in the colormap */
color_tried = NULL;
if ( sicon->format->BitsPerPixel == 8 ) {
SDL_Palette *palette;
Uint8 *p;
XColor wanted;
palette = sicon->format->palette;
color_tried = malloc(palette->ncolors);
if ( color_tried == NULL ) {
goto done;
}
if ( SDL_iconcolors != NULL ) {
free(SDL_iconcolors);
}
SDL_iconcolors = malloc(palette->ncolors
* sizeof(*SDL_iconcolors));
if ( SDL_iconcolors == NULL ) {
free(color_tried);
goto done;
}
memset(color_tried, 0, palette->ncolors);
memset(SDL_iconcolors, 0,
palette->ncolors * sizeof(*SDL_iconcolors));
p = (Uint8 *)sicon->pixels;
for ( i = sicon->w*sicon->h; i > 0; --i, ++p ) {
if ( ! color_tried[*p] ) {
wanted.pixel = *p;
wanted.red = (palette->colors[*p].r<<8);
wanted.green = (palette->colors[*p].g<<8);
wanted.blue = (palette->colors[*p].b<<8);
wanted.flags = (DoRed|DoGreen|DoBlue);
if (XAllocColor(SDL_Display,
SDL_DisplayColormap, &wanted)) {
++SDL_iconcolors[wanted.pixel];
}
color_tried[*p] = 1;
}
}
}
if ( color_tried != NULL ) {
free(color_tried);
}
/* Translate mask data to LSB order and set the icon mask */
i = (sicon->w/8)*sicon->h;
LSBmask = (Uint8 *)malloc(i);
if ( LSBmask == NULL ) {
goto done;
}
memset(LSBmask, 0, i);
while ( --i >= 0 ) {
for ( b=0; b<8; ++b )
LSBmask[i] |= (((mask[i]>>b)&0x01)<<(7-b));
}
mask_pixmap = XCreatePixmapFromBitmapData(SDL_Display, WMwindow,
LSBmask, sicon->w, sicon->h, 1L, 0L, 1);
/* Transfer the image to an X11 pixmap */
icon_image = XCreateImage(SDL_Display,
DefaultVisual(SDL_Display, SDL_Screen),
DefaultDepth(SDL_Display, SDL_Screen),
ZPixmap, 0, (char *)sicon->pixels, sicon->w, sicon->h,
((sicon->format)->BytesPerPixel == 3) ? 32 :
(sicon->format)->BytesPerPixel*8, 0);
icon_pixmap = XCreatePixmap(SDL_Display, SDL_Root, sicon->w, sicon->h,
DefaultDepth(SDL_Display, SDL_Screen));
GC = XCreateGC(SDL_Display, icon_pixmap, 0, &GCvalues);
XPutImage(SDL_Display, icon_pixmap, GC, icon_image,
0, 0, 0, 0, sicon->w, sicon->h);
XFreeGC(SDL_Display, GC);
XDestroyImage(icon_image);
free(LSBmask);
sicon->pixels = NULL;
#ifdef USE_ICON_WINDOW
/* Create an icon window and set the pixmap as its background */
icon_window = XCreateSimpleWindow(SDL_Display, SDL_Root,
0, 0, sicon->w, sicon->h, 0,
CopyFromParent, CopyFromParent);
XSetWindowBackgroundPixmap(SDL_Display, icon_window, icon_pixmap);
XClearWindow(SDL_Display, icon_window);
#endif
/* Set the window icon to the icon pixmap (and icon window) */
wmhints = XAllocWMHints();
wmhints->flags = (IconPixmapHint | IconMaskHint);
wmhints->icon_pixmap = icon_pixmap;
wmhints->icon_mask = mask_pixmap;
#ifdef USE_ICON_WINDOW
wmhints->flags |= IconWindowHint;
wmhints->icon_window = icon_window;
#endif
XSetWMHints(SDL_Display, WMwindow, wmhints);
XFree(wmhints);
XSync(SDL_Display, False);
done:
SDL_Unlock_EventThread();
if ( sicon != NULL ) {
SDL_FreeSurface(sicon);
}
#endif /*big*/
return;
}
May 10, 2001
May 10, 2001
223
/* Set window caption */
Apr 26, 2001
Apr 26, 2001
224
225
226
227
void ph_SetCaption(_THIS, const char *title, const char *icon)
{
SDL_Lock_EventThread();
if ( title != NULL ) {
May 10, 2001
May 10, 2001
228
PtSetResource(window, Pt_ARG_WINDOW_TITLE, title, 0);
Apr 26, 2001
Apr 26, 2001
229
230
231
232
}
SDL_Unlock_EventThread();
}
May 10, 2001
May 10, 2001
233
/* Iconify the window (stolen from PhHotKey sources by phearbear ;-) */
Apr 26, 2001
Apr 26, 2001
234
235
int ph_IconifyWindow(_THIS)
{
Sep 23, 2001
Sep 23, 2001
236
237
238
239
240
241
242
243
244
245
246
247
248
249
#if 1 /* Code submitted by Luca <barbato_luca@yahoo.com> */
WmApiContext_t context=WmCreateContext();
WmWindowDefinition_t
**wininfo=malloc(sizeof(WmWindowDefinition_t)*2);
int num;
SDL_Lock_EventThread();
WmGetFocusList(context,2,&num,wininfo);
WmPerformFrameAction(context, wininfo[0]->rid,Pt_ACTION_MIN);
WmDestroyContext (context);
SDL_Unlock_EventThread();
free(wininfo);
return (0);
#else
May 10, 2001
May 10, 2001
250
251
252
253
254
255
256
257
int result=0;
int myerr;
int num;
PtConnectionClient_t *Client=0;
WmMsg_t* Message=malloc(sizeof(WmMsg_t));
WmReply_t *Reply=malloc(sizeof(WmReply_t));
WmApiContext_t MsgStruct=malloc(sizeof(WmApiContext_t));
WmWindowDefinition_t **WNDDEF=malloc(sizeof(WmWindowDefinition_t)*2);
Apr 26, 2001
Apr 26, 2001
258
259
SDL_Lock_EventThread();
May 10, 2001
May 10, 2001
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
PtInit("/dev/photon");
Client=PtConnectionFindName("pwm",0,0);
if(!Client)
{
return result;
}
MsgStruct->input_group=PhInputGroup(0);
MsgStruct->connection=PtConnectionFindName("pwm",0,0);
myerr=WmGetFocusList(MsgStruct,2,&num,WNDDEF);
Message->hdr.type=WM_REQUEST_WIN_ACTION;
Message->hdr.subtype=Pt_ACTION_MIN;
Message->hdr.rid=WNDDEF[0]->rid;
myerr=WmSendMessage(Client,Message,Reply,0);
free(Message);
free(Reply);
Apr 26, 2001
Apr 26, 2001
282
SDL_Unlock_EventThread();
May 10, 2001
May 10, 2001
283
Apr 26, 2001
Apr 26, 2001
284
return(result);
Sep 23, 2001
Sep 23, 2001
285
#endif /* 1 */
Apr 26, 2001
Apr 26, 2001
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
}
SDL_GrabMode ph_GrabInputNoLock(_THIS, SDL_GrabMode mode)
{
#if 0 /*big*/
int numtries, result;
if ( this->screen == NULL ) {
return(SDL_GRAB_OFF);
}
if ( ! SDL_Window ) {
return(mode); /* Will be set later on mode switch */
}
if ( mode == SDL_GRAB_OFF ) {
XUngrabPointer(SDL_Display, CurrentTime);
if ( this->screen->flags & SDL_FULLSCREEN ) {
/* Rebind the mouse to the fullscreen window */
for ( numtries = 0; numtries < 10; ++numtries ) {
result = XGrabPointer(SDL_Display, FSwindow,
True, 0,
GrabModeAsync, GrabModeAsync,
FSwindow, None, CurrentTime);
if ( result == AlreadyGrabbed ) {
break;
}
SDL_Delay(100);
}
}
#ifdef GRAB_FULLSCREEN
if ( !(this->screen->flags & SDL_FULLSCREEN) )
#endif
XUngrabKeyboard(SDL_Display, CurrentTime);
} else {
if ( this->screen->flags & SDL_FULLSCREEN ) {
/* Unbind the mouse from the fullscreen window */
XUngrabPointer(SDL_Display, CurrentTime);
}
/* Try to grab the mouse */
for ( numtries = 0; numtries < 10; ++numtries ) {
result = XGrabPointer(SDL_Display, SDL_Window, True, 0,
GrabModeAsync, GrabModeAsync,
SDL_Window, None, CurrentTime);
if ( result != AlreadyGrabbed ) {
break;
}
SDL_Delay(100);
}
#ifdef GRAB_FULLSCREEN
if ( !(this->screen->flags & SDL_FULLSCREEN) )
#endif
XGrabKeyboard(SDL_Display, WMwindow, True,
GrabModeAsync, GrabModeAsync, CurrentTime);
}
XSync(SDL_Display, False);
#endif /*big*/
return(mode);
}
SDL_GrabMode ph_GrabInput(_THIS, SDL_GrabMode mode)
{
#if 0
SDL_Lock_EventThread();
mode = X11_GrabInputNoLock(this, mode);
SDL_Unlock_EventThread();
#endif
return(mode);
}
/* If 'info' is the right version, this function fills it and returns 1.
Otherwise, in case of a version mismatch, it returns -1.
*/
static void lock_display(void)
{
SDL_Lock_EventThread();
}
static void unlock_display(void)
{
#if 0
/* Make sure any X11 transactions are completed */
SDL_VideoDevice *this = current_video;
XSync(SDL_Display, False);
#endif
May 10, 2001
May 10, 2001
370
SDL_Unlock_EventThread();
Apr 26, 2001
Apr 26, 2001
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
}
int ph_GetWMInfo(_THIS, SDL_SysWMinfo *info)
{
#if 0
if ( info->version.major <= SDL_MAJOR_VERSION ) {
info->subsystem = SDL_SYSWM_X11;
info->info.x11.display = SDL_Display;
info->info.x11.window = SDL_Window;
if ( SDL_VERSIONNUM(info->version.major,
info->version.minor,
info->version.patch) >= 1002 ) {
info->info.x11.fswindow = FSwindow;
info->info.x11.wmwindow = WMwindow;
}
info->info.x11.lock_func = lock_display;
info->info.x11.unlock_func = unlock_display;
return(1);
} else {
SDL_SetError("Application not compiled with SDL %d.%d\n",
SDL_MAJOR_VERSION, SDL_MINOR_VERSION);
return(-1);
}
#endif
May 10, 2001
May 10, 2001
394
return -1; // for now ...
Apr 26, 2001
Apr 26, 2001
395
}
May 10, 2001
May 10, 2001
396
397