File:  [local] / rpl / src / encart.c
Revision 1.63: download - view: text, annotated - select for diffs - revision graph
Wed Aug 23 20:29:29 2017 UTC (6 years, 8 months ago) by bertrand
Branches: MAIN
CVS tags: HEAD
X Error of failed request:  BadFont (invalid Font parameter)
  Major opcode of failed request:  55 (X_CreateGC)
  Resource id in failed request:  0x0
  Serial number of failed request:  14896
  Current serial number in output stream:  14906

Patch insuffisant.

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

CVSweb interface <joel.bertrand@systella.fr>