Annotation of rpl/src/encart.c, revision 1.66
1.1 bertrand 1: /*
2: ================================================================================
1.60 bertrand 3: RPL/2 (R) version 4.1.28
1.58 bertrand 4: Copyright (C) 1989-2017 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.61 bertrand 43: static int
44: _XlibErrorHandler(Display *display, XErrorEvent *event)
45: {
1.63 bertrand 46: valeur_erreur(d_vrai);
1.61 bertrand 47: uprintf("An error occured detecting the mouse position\n");
48: return True;
49: }
1.1 bertrand 50:
1.62 bertrand 51: static void
52: _XtWarningHandler(String message)
53: {
54: return;
55: }
56:
1.1 bertrand 57: void
1.42 bertrand 58: encart(struct_processus *s_etat_processus, integer8 duree)
1.1 bertrand 59: {
60: # ifdef MOTIF_SUPPORT
61: # include "rpl.xpm"
62:
1.61 bertrand 63: Bool mouse_found;
64:
1.1 bertrand 65: Display *display;
66:
67: int argc;
68: int erreur;
69: int hauteur;
70: int hauteur_xpm;
1.61 bertrand 71: int i;
1.1 bertrand 72: int largeur;
73: int largeur_xpm;
1.61 bertrand 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;
1.1 bertrand 86:
87: Pixmap pixmap_rpl;
88: Pixmap pixmap_rpl_masque;
89:
90: Position hauteur_popup;
91: Position largeur_popup;
92:
93: String *argv;
94:
95: struct timespec attente;
96:
97: struct timeval temps_ecoule;
98: struct timeval horodatage_initial;
99: struct timeval horodatage_final;
100:
1.42 bertrand 101: long decor;
102: long fonctions;
1.1 bertrand 103:
1.61 bertrand 104: unsigned int mask_return;
105:
106: Window *root_windows;
107: Window window_returned;
108:
1.1 bertrand 109: Widget cadre;
110: Widget form;
111: Widget objet_principal;
112: Widget pixmap;
113:
114: XEvent evenement;
115:
1.61 bertrand 116: XineramaScreenInfo *ts;
117:
1.1 bertrand 118: XtAppContext app;
119:
1.62 bertrand 120: XtErrorHandler old_message_handler;
121:
1.1 bertrand 122: if (strstr(XmVERSION_STRING, "LessTif") != NULL)
123: {
124: printf("Lesstif is broken, please consider an upgrade to OpenMotif.\n");
125: return;
126: }
127:
128: argc = 0;
129: argv = NULL;
130:
131: display = XOpenDisplay(NULL);
132:
133: // Si display est nul, il n'y pas de serveur X.
134:
135: if (display != NULL)
136: {
137: objet_principal = XtVaOpenApplication(&app, "rpl",
1.62 bertrand 138: NULL, 0, &argc, argv, NULL, overrideShellWidgetClass, NULL);
1.1 bertrand 139: XSynchronize(XtDisplay(objet_principal), False);
140:
1.62 bertrand 141: old_message_handler = XtAppSetWarningHandler(app, _XtWarningHandler);
142:
1.1 bertrand 143: form = XtVaCreateManagedWidget("rplSplashScreen",
144: xmFormWidgetClass, objet_principal,
145: NULL);
146:
1.66 ! bertrand 147: XtVaGetValues(objet_principal,
! 148: XmNmwmDecorations, &decor,
! 149: XmNmwmFunctions, &fonctions,
! 150: NULL);
! 151:
! 152: decor &= ~(MWM_DECOR_ALL + MWM_DECOR_MAXIMIZE + MWM_DECOR_RESIZEH
! 153: + MWM_DECOR_TITLE + MWM_DECOR_MENU + MWM_DECOR_BORDER);
! 154: fonctions &= ~(MWM_FUNC_ALL + MWM_FUNC_RESIZE + MWM_FUNC_CLOSE
! 155: + MWM_FUNC_MINIMIZE + MWM_FUNC_MAXIMIZE);
! 156:
! 157: XtVaSetValues(objet_principal,
! 158: XmNmwmDecorations, decor,
! 159: XmNmwmFunctions, fonctions,
! 160: NULL);
! 161:
1.1 bertrand 162: cadre = XtVaCreateManagedWidget("rplExternalFrame",
163: xmFrameWidgetClass, form,
164: XmNtopAttachment, XmATTACH_FORM,
165: XmNbottomAttachment, XmATTACH_FORM,
166: XmNleftAttachment, XmATTACH_FORM,
167: XmNrightAttachment, XmATTACH_FORM,
168: XmNtopOffset, 5,
169: XmNleftOffset, 5,
170: XmNrightOffset, 5,
171: XmNbottomOffset, 5,
172: XmNmarginWidth, 5,
173: XmNmarginHeight, 5,
174: NULL);
175:
1.65 bertrand 176: uprintf("0\n");
1.63 bertrand 177: if ((erreur = XpmCreatePixmapFromData(XtDisplay(form),
1.1 bertrand 178: DefaultRootWindow(XtDisplay(form)), rpl_xpm,
179: &pixmap_rpl, &pixmap_rpl_masque, NULL)) != 0)
180: {
181: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
182: return;
183: }
184:
185: pixmap = XtVaCreateManagedWidget("rplPixmap",
186: xmLabelWidgetClass, cadre,
187: XmNlabelType, XmPIXMAP,
188: XmNlabelPixmap, pixmap_rpl,
189: NULL);
190:
1.65 bertrand 191: uprintf("1\n");
1.61 bertrand 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:
1.63 bertrand 199: //XSetErrorHandler(_XlibErrorHandler);
1.61 bertrand 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: {
1.63 bertrand 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)
1.61 bertrand 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: }
1.65 bertrand 284: uprintf("2\n");
1.61 bertrand 285:
1.1 bertrand 286: #if 0
287: XtRealizeWidget(objet_principal);
288:
289: XtVaGetValues(objet_principal,
290: XmNheight, &hauteur_popup,
291: XmNwidth, &largeur_popup,
292: NULL);
293:
294: XtVaSetValues(objet_principal,
1.61 bertrand 295: XmNx, offset_x + ((largeur - largeur_popup) / 2),
296: XmNy, offset_y + ((hauteur - hauteur_popup) / 2),
1.1 bertrand 297: NULL);
298: #else
299: sscanf(rpl_xpm[0], "%d %d", &largeur_xpm, &hauteur_xpm);
300:
1.42 bertrand 301: largeur_popup = (Position) (largeur_xpm + 28);
302: hauteur_popup = (Position) (hauteur_xpm + 28);
1.1 bertrand 303:
304: XtVaSetValues(objet_principal,
1.61 bertrand 305: XmNx, offset_x + ((largeur - largeur_popup) / 2),
306: XmNy, offset_y + ((hauteur - hauteur_popup) / 2),
1.1 bertrand 307: NULL);
308:
309: XtRealizeWidget(objet_principal);
310: #endif
1.65 bertrand 311: uprintf("3\n");
1.1 bertrand 312:
313: XFlush(XtDisplay(form));
1.65 bertrand 314: uprintf("3a\n");
1.1 bertrand 315:
316: attente.tv_sec = 0;
317: attente.tv_nsec = 1000;
318:
319: gettimeofday(&horodatage_initial, NULL);
320:
321: do
322: {
1.65 bertrand 323: uprintf("3b\n");
1.1 bertrand 324: if (XtAppPending(app) != 0)
325: {
1.65 bertrand 326: uprintf("3c\n");
1.1 bertrand 327: XtAppNextEvent(app, &evenement);
1.65 bertrand 328: uprintf("3d\n");
1.1 bertrand 329: XtDispatchEvent(&evenement);
1.65 bertrand 330: uprintf("3e\n");
1.1 bertrand 331: }
1.65 bertrand 332: uprintf("3f\n");
1.1 bertrand 333:
334: nanosleep(&attente, NULL);
335: gettimeofday(&horodatage_final, NULL);
336:
337: temps_ecoule.tv_sec = horodatage_final.tv_sec
338: - horodatage_initial.tv_sec;
339: temps_ecoule.tv_usec = horodatage_final.tv_usec
340: - horodatage_initial.tv_usec;
341:
342: if (temps_ecoule.tv_usec < 0)
343: {
344: temps_ecoule.tv_usec += 1000000;
345: temps_ecoule.tv_sec--;
346: }
1.42 bertrand 347: } while (((((double) temps_ecoule.tv_usec) / ((double) 1000000))
348: + ((double) temps_ecoule.tv_sec))
349: < (((double) duree) / ((double) 1000000)));
1.1 bertrand 350:
1.65 bertrand 351: uprintf("4\n");
1.1 bertrand 352: XtUnrealizeWidget(objet_principal);
1.65 bertrand 353: uprintf("5\n");
1.1 bertrand 354:
355: while(XtAppPending(app) == 0)
356: {
357: nanosleep(&attente, NULL);
358: }
359:
360: while(XtAppPending(app) != 0)
361: {
362: XtAppNextEvent(app, &evenement);
363: XtDispatchEvent(&evenement);
364: nanosleep(&attente, NULL);
365: }
366:
1.65 bertrand 367: XtDestroyWidget(pixmap);
368: XtDestroyWidget(cadre);
369: XtDestroyWidget(form);
370: XtDestroyWidget(objet_principal);
371:
372: uprintf("6\n");
1.64 bertrand 373: XmDestroyPixmap(XtScreen(form), pixmap_rpl);
374: XmDestroyPixmap(XtScreen(form), pixmap_rpl_masque);
375:
1.62 bertrand 376: XtAppSetWarningHandler(app, old_message_handler);
1.1 bertrand 377: XtDestroyApplicationContext(app);
1.66 ! bertrand 378: XCloseDisplay(display);
1.65 bertrand 379: uprintf("7\n");
1.1 bertrand 380: }
381: # endif
382:
383: return;
384: }
385:
386: // vim: ts=4
CVSweb interface <joel.bertrand@systella.fr>