File:  [local] / rpl / src / encart.c
Revision 1.62: download - view: text, annotated - select for diffs - revision graph
Wed Aug 23 09:29:15 2017 UTC (6 years, 8 months ago) by bertrand
Branches: MAIN
CVS tags: HEAD
Modification de la popup pour éviter qu'il y ait une icone transitoire.

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

CVSweb interface <joel.bertrand@systella.fr>