Annotation of rpl/src/encart.c, revision 1.74
1.1 bertrand 1: /*
2: ================================================================================
1.73 bertrand 3: RPL/2 (R) version 4.1.32
1.74 ! bertrand 4: Copyright (C) 1989-2020 Dr. BERTRAND Joël
1.1 bertrand 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:
1.11 bertrand 23: #include "rpl-conv.h"
1.1 bertrand 24:
25: #ifdef MOTIF_SUPPORT
26: # include <X11/Xlib.h>
1.28 bertrand 27: # include "X11/xpm.h"
28: # include "Xm/XmAll.h"
1.61 bertrand 29: # include <X11/extensions/Xinerama.h>
1.1 bertrand 30: #endif
31:
1.63 bertrand 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:
1.72 bertrand 43: #ifdef MOTIF_SUPPORT
1.61 bertrand 44: static int
45: _XlibErrorHandler(Display *display, XErrorEvent *event)
46: {
1.63 bertrand 47: valeur_erreur(d_vrai);
1.61 bertrand 48: uprintf("An error occured detecting the mouse position\n");
49: return True;
50: }
1.1 bertrand 51:
1.62 bertrand 52: static void
53: _XtWarningHandler(String message)
54: {
55: return;
56: }
1.72 bertrand 57: #endif
1.62 bertrand 58:
1.1 bertrand 59: void
1.42 bertrand 60: encart(struct_processus *s_etat_processus, integer8 duree)
1.1 bertrand 61: {
62: # ifdef MOTIF_SUPPORT
63: # include "rpl.xpm"
64:
1.61 bertrand 65: Bool mouse_found;
66:
1.1 bertrand 67: Display *display;
68:
69: int argc;
70: int erreur;
71: int hauteur;
72: int hauteur_xpm;
1.61 bertrand 73: int i;
1.1 bertrand 74: int largeur;
75: int largeur_xpm;
1.61 bertrand 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;
1.1 bertrand 88:
89: Pixmap pixmap_rpl;
90: Pixmap pixmap_rpl_masque;
91:
92: Position hauteur_popup;
93: Position largeur_popup;
94:
1.67 bertrand 95: Screen *screen;
96:
1.1 bertrand 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:
1.42 bertrand 105: long decor;
106: long fonctions;
1.1 bertrand 107:
1.61 bertrand 108: unsigned int mask_return;
109:
110: Window *root_windows;
111: Window window_returned;
112:
1.1 bertrand 113: Widget cadre;
114: Widget form;
115: Widget objet_principal;
116: Widget pixmap;
117:
118: XEvent evenement;
119:
1.61 bertrand 120: XineramaScreenInfo *ts;
121:
1.1 bertrand 122: XtAppContext app;
123:
1.62 bertrand 124: XtErrorHandler old_message_handler;
125:
1.1 bertrand 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",
1.62 bertrand 142: NULL, 0, &argc, argv, NULL, overrideShellWidgetClass, NULL);
1.1 bertrand 143: XSynchronize(XtDisplay(objet_principal), False);
144:
1.62 bertrand 145: old_message_handler = XtAppSetWarningHandler(app, _XtWarningHandler);
146:
1.1 bertrand 147: form = XtVaCreateManagedWidget("rplSplashScreen",
148: xmFormWidgetClass, objet_principal,
149: NULL);
150:
1.66 bertrand 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:
1.1 bertrand 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:
1.63 bertrand 180: if ((erreur = XpmCreatePixmapFromData(XtDisplay(form),
1.1 bertrand 181: DefaultRootWindow(XtDisplay(form)), rpl_xpm,
1.67 bertrand 182: &pixmap_rpl, &pixmap_rpl_masque, NULL)) != XpmSuccess)
1.1 bertrand 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:
1.61 bertrand 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:
1.63 bertrand 201: //XSetErrorHandler(_XlibErrorHandler);
1.61 bertrand 202: nb_screens = XScreenCount(display);
203:
204: root_windows = sys_malloc(((unsigned) nb_screens) * sizeof(Window));
205:
206: for(i = 0; i < nb_screens; i++)
207: {
208: root_windows[i] = XRootWindow(display, i);
209: }
210:
211: for(i = 0; i < nb_screens; i++)
212: {
1.63 bertrand 213: valeur_erreur(d_faux);
214:
215: do
216: {
217: mouse_found = XQueryPointer(display, root_windows[i],
218: &window_returned, &window_returned,
219: &root_x, &root_y, &win_x, &win_y, &mask_return);
220: } while(valeur_erreur(d_faux) == d_vrai);
221:
222: if (mouse_found == True)
1.61 bertrand 223: {
224: break;
225: }
226: }
227:
228: if (mouse_found == True)
229: {
230: mouse_found = False;
231:
232: for(i = 0; i < ns; i++)
233: {
234: x_min = ts[i].x_org;
235: x_max = x_min + ts[i].width;
236: y_min = ts[i].y_org;
237: y_max = y_min + ts[i].height;
238:
239: if ((root_x >= x_min) && (root_x <= x_max) &&
240: (root_y >= y_min) && (root_y <= y_max))
241: {
242: largeur = ts[i].width;
243: hauteur = ts[i].height;
244: offset_x = ts[i].x_org;
245: offset_y = ts[i].y_org;
246:
247: mouse_found = True;
248: break;
249: }
250: }
251:
252: if (mouse_found == False)
253: {
254: // Aucune souris sur un écran physique.
255:
256: largeur = ts[0].width;
257: hauteur = ts[0].height;
258: offset_x = 0;
259: offset_y = 0;
260: }
261: }
262: else
263: {
264: // Aucune souris, on considère le premier écran physique
265: // géré par Xinerama.
266:
267: largeur = ts[0].width;
268: hauteur = ts[0].height;
269: offset_x = 0;
270: offset_y = 0;
271: }
272:
273: sys_free(root_windows);
274: XFree(ts);
275: }
276: else
277: {
278: // Xinerama inactif, on considère qu'il n'y a qu'un seul
279: // écran physique.
280:
281: largeur = WidthOfScreen(XtScreen(form));
282: hauteur = HeightOfScreen(XtScreen(form));
283: offset_x = 0;
284: offset_y = 0;
285: }
286:
1.1 bertrand 287: #if 0
288: XtRealizeWidget(objet_principal);
289:
290: XtVaGetValues(objet_principal,
291: XmNheight, &hauteur_popup,
292: XmNwidth, &largeur_popup,
293: NULL);
294:
295: XtVaSetValues(objet_principal,
1.61 bertrand 296: XmNx, offset_x + ((largeur - largeur_popup) / 2),
297: XmNy, offset_y + ((hauteur - hauteur_popup) / 2),
1.1 bertrand 298: NULL);
299: #else
300: sscanf(rpl_xpm[0], "%d %d", &largeur_xpm, &hauteur_xpm);
301:
1.42 bertrand 302: largeur_popup = (Position) (largeur_xpm + 28);
303: hauteur_popup = (Position) (hauteur_xpm + 28);
1.1 bertrand 304:
305: XtVaSetValues(objet_principal,
1.61 bertrand 306: XmNx, offset_x + ((largeur - largeur_popup) / 2),
307: XmNy, offset_y + ((hauteur - hauteur_popup) / 2),
1.1 bertrand 308: NULL);
309:
310: XtRealizeWidget(objet_principal);
311: #endif
312:
313: XFlush(XtDisplay(form));
314:
315: attente.tv_sec = 0;
316: attente.tv_nsec = 1000;
317:
318: gettimeofday(&horodatage_initial, NULL);
319:
320: do
321: {
322: if (XtAppPending(app) != 0)
323: {
324: XtAppNextEvent(app, &evenement);
325: XtDispatchEvent(&evenement);
326: }
327:
328: nanosleep(&attente, NULL);
329: gettimeofday(&horodatage_final, NULL);
330:
331: temps_ecoule.tv_sec = horodatage_final.tv_sec
332: - horodatage_initial.tv_sec;
333: temps_ecoule.tv_usec = horodatage_final.tv_usec
334: - horodatage_initial.tv_usec;
335:
336: if (temps_ecoule.tv_usec < 0)
337: {
338: temps_ecoule.tv_usec += 1000000;
339: temps_ecoule.tv_sec--;
340: }
1.42 bertrand 341: } while (((((double) temps_ecoule.tv_usec) / ((double) 1000000))
342: + ((double) temps_ecoule.tv_sec))
343: < (((double) duree) / ((double) 1000000)));
1.1 bertrand 344:
345: XtUnrealizeWidget(objet_principal);
346:
347: while(XtAppPending(app) == 0)
348: {
349: nanosleep(&attente, NULL);
350: }
351:
352: while(XtAppPending(app) != 0)
353: {
354: XtAppNextEvent(app, &evenement);
355: XtDispatchEvent(&evenement);
356: nanosleep(&attente, NULL);
357: }
358:
1.67 bertrand 359: screen = XtScreen(form);
360:
1.65 bertrand 361: XtDestroyWidget(pixmap);
362: XtDestroyWidget(cadre);
363: XtDestroyWidget(form);
364: XtDestroyWidget(objet_principal);
365:
1.67 bertrand 366: XmDestroyPixmap(screen, pixmap_rpl);
367: XmDestroyPixmap(screen, pixmap_rpl_masque);
1.64 bertrand 368:
1.62 bertrand 369: XtAppSetWarningHandler(app, old_message_handler);
1.1 bertrand 370: XtDestroyApplicationContext(app);
1.66 bertrand 371: XCloseDisplay(display);
1.1 bertrand 372: }
373: # endif
374:
375: return;
376: }
377:
378: // vim: ts=4
CVSweb interface <joel.bertrand@systella.fr>