1: /*
2: ================================================================================
3: RPL/2 (R) version 4.1.36
4: Copyright (C) 1989-2025 Dr. BERTRAND Joël
5:
6: This file is part of RPL/2.
7:
8: RPL/2 is free software; you can redistribute it and/or modify it
9: under the terms of the CeCILL V2 License as published by the french
10: CEA, CNRS and INRIA.
11:
12: RPL/2 is distributed in the hope that it will be useful, but WITHOUT
13: ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14: FITNESS FOR A PARTICULAR PURPOSE. See the CeCILL V2 License
15: for more details.
16:
17: You should have received a copy of the CeCILL License
18: along with RPL/2. If not, write to info@cecill.info.
19: ================================================================================
20: */
21:
22:
23: #include "rpl-conv.h"
24:
25: #ifdef MOTIF_SUPPORT
26: # include <X11/Xlib.h>
27: # include "X11/xpm.h"
28: # include "Xm/XmAll.h"
29: # include <X11/extensions/Xinerama.h>
30: #endif
31:
32: static logical1
33: valeur_erreur(logical1 nouvelle_valeur)
34: {
35: static logical1 erreur = d_faux;
36: logical1 registre;
37:
38: registre = erreur;
39: erreur = nouvelle_valeur;
40: return(registre);
41: }
42:
43: #ifdef MOTIF_SUPPORT
44: static int
45: _XlibErrorHandler(Display *display, XErrorEvent *event)
46: {
47: valeur_erreur(d_vrai);
48: uprintf("An error occured detecting the mouse position\n");
49: return True;
50: }
51:
52: static void
53: _XtWarningHandler(String message)
54: {
55: return;
56: }
57: #endif
58:
59: void
60: encart(struct_processus *s_etat_processus, integer8 duree)
61: {
62: # ifdef MOTIF_SUPPORT
63: # include "rpl.xpm"
64:
65: Bool mouse_found;
66:
67: Display *display;
68:
69: int argc;
70: int erreur;
71: int hauteur;
72: int hauteur_xpm;
73: int i;
74: int largeur;
75: int largeur_xpm;
76: int ns;
77: int nb_screens;
78: int offset_x;
79: int offset_y;
80: int root_x;
81: int root_y;
82: int win_x;
83: int win_y;
84: int x_max;
85: int x_min;
86: int y_max;
87: int y_min;
88:
89: Pixmap pixmap_rpl;
90: Pixmap pixmap_rpl_masque;
91:
92: Position hauteur_popup;
93: Position largeur_popup;
94:
95: Screen *screen;
96:
97: String *argv;
98:
99: struct timespec attente;
100:
101: struct timeval temps_ecoule;
102: struct timeval horodatage_initial;
103: struct timeval horodatage_final;
104:
105: long decor;
106: long fonctions;
107:
108: unsigned int mask_return;
109:
110: Window *root_windows;
111: Window window_returned;
112:
113: Widget cadre;
114: Widget form;
115: Widget objet_principal;
116: Widget pixmap;
117:
118: XEvent evenement;
119:
120: XineramaScreenInfo *ts;
121:
122: XtAppContext app;
123:
124: XtErrorHandler old_message_handler;
125:
126: if (strstr(XmVERSION_STRING, "LessTif") != NULL)
127: {
128: printf("Lesstif is broken, please consider an upgrade to OpenMotif.\n");
129: return;
130: }
131:
132: argc = 0;
133: argv = NULL;
134:
135: display = XOpenDisplay(NULL);
136:
137: // Si display est nul, il n'y pas de serveur X.
138:
139: if (display != NULL)
140: {
141: objet_principal = XtVaOpenApplication(&app, "rpl",
142: NULL, 0, &argc, argv, NULL, overrideShellWidgetClass, NULL);
143: XSynchronize(XtDisplay(objet_principal), False);
144:
145: old_message_handler = XtAppSetWarningHandler(app, _XtWarningHandler);
146:
147: form = XtVaCreateManagedWidget("rplSplashScreen",
148: xmFormWidgetClass, objet_principal,
149: NULL);
150:
151: XtVaGetValues(objet_principal,
152: XmNmwmDecorations, &decor,
153: XmNmwmFunctions, &fonctions,
154: NULL);
155:
156: decor &= ~(MWM_DECOR_ALL + MWM_DECOR_MAXIMIZE + MWM_DECOR_RESIZEH
157: + MWM_DECOR_TITLE + MWM_DECOR_MENU + MWM_DECOR_BORDER);
158: fonctions &= ~(MWM_FUNC_ALL + MWM_FUNC_RESIZE + MWM_FUNC_CLOSE
159: + MWM_FUNC_MINIMIZE + MWM_FUNC_MAXIMIZE);
160:
161: XtVaSetValues(objet_principal,
162: XmNmwmDecorations, decor,
163: XmNmwmFunctions, fonctions,
164: NULL);
165:
166: cadre = XtVaCreateManagedWidget("rplExternalFrame",
167: xmFrameWidgetClass, form,
168: XmNtopAttachment, XmATTACH_FORM,
169: XmNbottomAttachment, XmATTACH_FORM,
170: XmNleftAttachment, XmATTACH_FORM,
171: XmNrightAttachment, XmATTACH_FORM,
172: XmNtopOffset, 5,
173: XmNleftOffset, 5,
174: XmNrightOffset, 5,
175: XmNbottomOffset, 5,
176: XmNmarginWidth, 5,
177: XmNmarginHeight, 5,
178: NULL);
179:
180: if ((erreur = XpmCreatePixmapFromData(XtDisplay(form),
181: DefaultRootWindow(XtDisplay(form)), rpl_xpm,
182: &pixmap_rpl, &pixmap_rpl_masque, NULL)) != XpmSuccess)
183: {
184: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
185: return;
186: }
187:
188: pixmap = XtVaCreateManagedWidget("rplPixmap",
189: xmLabelWidgetClass, cadre,
190: XmNlabelType, XmPIXMAP,
191: XmNlabelPixmap, pixmap_rpl,
192: NULL);
193:
194: if (XineramaIsActive(display) == True)
195: {
196: // Récupération de la localisation des différents écrans
197: // physiques.
198:
199: ts = XineramaQueryScreens(display, &ns);
200:
201: //XSetErrorHandler(_XlibErrorHandler);
202: nb_screens = XScreenCount(display);
203: mouse_found = False;
204:
205: root_windows = sys_malloc(((unsigned) nb_screens) * sizeof(Window));
206:
207: for(i = 0; i < nb_screens; i++)
208: {
209: root_windows[i] = XRootWindow(display, i);
210: }
211:
212: for(i = 0; i < nb_screens; i++)
213: {
214: valeur_erreur(d_faux);
215:
216: do
217: {
218: mouse_found = XQueryPointer(display, root_windows[i],
219: &window_returned, &window_returned,
220: &root_x, &root_y, &win_x, &win_y, &mask_return);
221: } while(valeur_erreur(d_faux) == d_vrai);
222:
223: if (mouse_found == True)
224: {
225: break;
226: }
227: }
228:
229: if (mouse_found == True)
230: {
231: mouse_found = False;
232:
233: for(i = 0; i < ns; i++)
234: {
235: x_min = ts[i].x_org;
236: x_max = x_min + ts[i].width;
237: y_min = ts[i].y_org;
238: y_max = y_min + ts[i].height;
239:
240: if ((root_x >= x_min) && (root_x <= x_max) &&
241: (root_y >= y_min) && (root_y <= y_max))
242: {
243: largeur = ts[i].width;
244: hauteur = ts[i].height;
245: offset_x = ts[i].x_org;
246: offset_y = ts[i].y_org;
247:
248: mouse_found = True;
249: break;
250: }
251: }
252:
253: if (mouse_found == False)
254: {
255: // Aucune souris sur un écran physique.
256:
257: largeur = ts[0].width;
258: hauteur = ts[0].height;
259: offset_x = 0;
260: offset_y = 0;
261: }
262: }
263: else
264: {
265: // Aucune souris, on considère le premier écran physique
266: // géré par Xinerama.
267:
268: largeur = ts[0].width;
269: hauteur = ts[0].height;
270: offset_x = 0;
271: offset_y = 0;
272: }
273:
274: sys_free(root_windows);
275: XFree(ts);
276: }
277: else
278: {
279: // Xinerama inactif, on considère qu'il n'y a qu'un seul
280: // écran physique.
281:
282: largeur = WidthOfScreen(XtScreen(form));
283: hauteur = HeightOfScreen(XtScreen(form));
284: offset_x = 0;
285: offset_y = 0;
286: }
287:
288: #if 0
289: XtRealizeWidget(objet_principal);
290:
291: XtVaGetValues(objet_principal,
292: XmNheight, &hauteur_popup,
293: XmNwidth, &largeur_popup,
294: NULL);
295:
296: XtVaSetValues(objet_principal,
297: XmNx, offset_x + ((largeur - largeur_popup) / 2),
298: XmNy, offset_y + ((hauteur - hauteur_popup) / 2),
299: NULL);
300: #else
301: sscanf(rpl_xpm[0], "%d %d", &largeur_xpm, &hauteur_xpm);
302:
303: largeur_popup = (Position) (largeur_xpm + 28);
304: hauteur_popup = (Position) (hauteur_xpm + 28);
305:
306: XtVaSetValues(objet_principal,
307: XmNx, offset_x + ((largeur - largeur_popup) / 2),
308: XmNy, offset_y + ((hauteur - hauteur_popup) / 2),
309: NULL);
310:
311: XtRealizeWidget(objet_principal);
312: #endif
313:
314: XFlush(XtDisplay(form));
315:
316: attente.tv_sec = 0;
317: attente.tv_nsec = 1000;
318:
319: gettimeofday(&horodatage_initial, NULL);
320:
321: do
322: {
323: if (XtAppPending(app) != 0)
324: {
325: XtAppNextEvent(app, &evenement);
326: XtDispatchEvent(&evenement);
327: }
328:
329: nanosleep(&attente, NULL);
330: gettimeofday(&horodatage_final, NULL);
331:
332: temps_ecoule.tv_sec = horodatage_final.tv_sec
333: - horodatage_initial.tv_sec;
334: temps_ecoule.tv_usec = horodatage_final.tv_usec
335: - horodatage_initial.tv_usec;
336:
337: if (temps_ecoule.tv_usec < 0)
338: {
339: temps_ecoule.tv_usec += 1000000;
340: temps_ecoule.tv_sec--;
341: }
342: } while (((((double) temps_ecoule.tv_usec) / ((double) 1000000))
343: + ((double) temps_ecoule.tv_sec))
344: < (((double) duree) / ((double) 1000000)));
345:
346: XtUnrealizeWidget(objet_principal);
347:
348: while(XtAppPending(app) == 0)
349: {
350: nanosleep(&attente, NULL);
351: }
352:
353: while(XtAppPending(app) != 0)
354: {
355: XtAppNextEvent(app, &evenement);
356: XtDispatchEvent(&evenement);
357: nanosleep(&attente, NULL);
358: }
359:
360: screen = XtScreen(form);
361:
362: XtDestroyWidget(pixmap);
363: XtDestroyWidget(cadre);
364: XtDestroyWidget(form);
365: XtDestroyWidget(objet_principal);
366:
367: XmDestroyPixmap(screen, pixmap_rpl);
368: XmDestroyPixmap(screen, pixmap_rpl_masque);
369:
370: XtAppSetWarningHandler(app, old_message_handler);
371: XtDestroyApplicationContext(app);
372: XCloseDisplay(display);
373: }
374: # endif
375:
376: return;
377: }
378:
379: // vim: ts=4
CVSweb interface <joel.bertrand@systella.fr>