Annotation of rpl/src/encart.c, revision 1.81
1.1 bertrand 1: /*
2: ================================================================================
1.80 bertrand 3: RPL/2 (R) version 4.1.36
1.81 ! bertrand 4: Copyright (C) 1989-2025 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);
1.76 bertrand 203: mouse_found = False;
1.61 bertrand 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: {
1.63 bertrand 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)
1.61 bertrand 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:
1.1 bertrand 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,
1.61 bertrand 297: XmNx, offset_x + ((largeur - largeur_popup) / 2),
298: XmNy, offset_y + ((hauteur - hauteur_popup) / 2),
1.1 bertrand 299: NULL);
300: #else
301: sscanf(rpl_xpm[0], "%d %d", &largeur_xpm, &hauteur_xpm);
302:
1.42 bertrand 303: largeur_popup = (Position) (largeur_xpm + 28);
304: hauteur_popup = (Position) (hauteur_xpm + 28);
1.1 bertrand 305:
306: XtVaSetValues(objet_principal,
1.61 bertrand 307: XmNx, offset_x + ((largeur - largeur_popup) / 2),
308: XmNy, offset_y + ((hauteur - hauteur_popup) / 2),
1.1 bertrand 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: }
1.42 bertrand 342: } while (((((double) temps_ecoule.tv_usec) / ((double) 1000000))
343: + ((double) temps_ecoule.tv_sec))
344: < (((double) duree) / ((double) 1000000)));
1.1 bertrand 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:
1.67 bertrand 360: screen = XtScreen(form);
361:
1.65 bertrand 362: XtDestroyWidget(pixmap);
363: XtDestroyWidget(cadre);
364: XtDestroyWidget(form);
365: XtDestroyWidget(objet_principal);
366:
1.67 bertrand 367: XmDestroyPixmap(screen, pixmap_rpl);
368: XmDestroyPixmap(screen, pixmap_rpl_masque);
1.64 bertrand 369:
1.62 bertrand 370: XtAppSetWarningHandler(app, old_message_handler);
1.1 bertrand 371: XtDestroyApplicationContext(app);
1.66 bertrand 372: XCloseDisplay(display);
1.1 bertrand 373: }
374: # endif
375:
376: return;
377: }
378:
379: // vim: ts=4
CVSweb interface <joel.bertrand@systella.fr>