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