Annotation of rpl/src/encart.c, revision 1.65

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:    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: 
1.42      bertrand  104:    long                decor;
                    105:    long                fonctions;
1.1       bertrand  106: 
1.61      bertrand  107:    unsigned int        mask_return;
                    108: 
                    109:    Window              *root_windows;
                    110:    Window              window_returned;
                    111: 
1.1       bertrand  112:    Widget              cadre;
                    113:    Widget              form;
                    114:    Widget              objet_principal;
                    115:    Widget              pixmap;
                    116: 
                    117:    XEvent              evenement;
                    118: 
1.61      bertrand  119:    XineramaScreenInfo  *ts;
                    120: 
1.1       bertrand  121:    XtAppContext        app;
                    122: 
1.62      bertrand  123:    XtErrorHandler      old_message_handler;
                    124: 
1.1       bertrand  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",
1.62      bertrand  141:                NULL, 0, &argc, argv, NULL, overrideShellWidgetClass, NULL);
1.1       bertrand  142:        XSynchronize(XtDisplay(objet_principal), False);
                    143: 
1.62      bertrand  144:        old_message_handler = XtAppSetWarningHandler(app, _XtWarningHandler);
                    145: 
1.1       bertrand  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: 
1.65    ! bertrand  169: uprintf("0\n");
1.63      bertrand  170:        if ((erreur = XpmCreatePixmapFromData(XtDisplay(form),
1.1       bertrand  171:                DefaultRootWindow(XtDisplay(form)), rpl_xpm,
                    172:                &pixmap_rpl, &pixmap_rpl_masque, NULL)) != 0)
                    173:        {
                    174:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    175:            return;
                    176:        }
                    177: 
                    178:        pixmap = XtVaCreateManagedWidget("rplPixmap",
                    179:                xmLabelWidgetClass, cadre,
                    180:                XmNlabelType, XmPIXMAP,
                    181:                XmNlabelPixmap, pixmap_rpl,
                    182:                NULL);
                    183: 
                    184:        XtVaGetValues(objet_principal,
                    185:                XmNmwmDecorations, &decor,
                    186:                XmNmwmFunctions, &fonctions,
                    187:                NULL);
                    188: 
                    189:        decor &= ~(MWM_DECOR_ALL + MWM_DECOR_MAXIMIZE + MWM_DECOR_RESIZEH
                    190:                + MWM_DECOR_TITLE + MWM_DECOR_MENU + MWM_DECOR_BORDER);
                    191:        fonctions &= ~(MWM_FUNC_ALL + MWM_FUNC_RESIZE + MWM_FUNC_CLOSE
                    192:                + MWM_FUNC_MINIMIZE + MWM_FUNC_MAXIMIZE);
                    193: 
                    194:        XtVaSetValues(objet_principal,
                    195:                XmNmwmDecorations, decor,
                    196:                XmNmwmFunctions, fonctions,
                    197:                NULL);
                    198: 
1.65    ! bertrand  199: uprintf("1\n");
1.61      bertrand  200:        if (XineramaIsActive(display) == True)
                    201:        {
                    202:            // Récupération de la localisation des différents écrans
                    203:            // physiques.
                    204: 
                    205:            ts = XineramaQueryScreens(display, &ns);
                    206: 
1.63      bertrand  207:            //XSetErrorHandler(_XlibErrorHandler);
1.61      bertrand  208:            nb_screens = XScreenCount(display);
                    209: 
                    210:            root_windows = sys_malloc(((unsigned) nb_screens) * sizeof(Window));
                    211: 
                    212:            for(i = 0; i < nb_screens; i++)
                    213:            {
                    214:                root_windows[i] = XRootWindow(display, i);
                    215:            }
                    216: 
                    217:            for(i = 0; i < nb_screens; i++)
                    218:            {
1.63      bertrand  219:                valeur_erreur(d_faux);
                    220: 
                    221:                do
                    222:                {
                    223:                    mouse_found = XQueryPointer(display, root_windows[i],
                    224:                            &window_returned, &window_returned,
                    225:                            &root_x, &root_y, &win_x, &win_y, &mask_return);
                    226:                } while(valeur_erreur(d_faux) == d_vrai);
                    227: 
                    228:                if (mouse_found == True)
1.61      bertrand  229:                {
                    230:                    break;
                    231:                }
                    232:            }
                    233: 
                    234:            if (mouse_found == True)
                    235:            {
                    236:                mouse_found = False;
                    237: 
                    238:                for(i = 0; i < ns; i++)
                    239:                {
                    240:                    x_min = ts[i].x_org;
                    241:                    x_max = x_min + ts[i].width;
                    242:                    y_min = ts[i].y_org;
                    243:                    y_max = y_min + ts[i].height;
                    244: 
                    245:                    if ((root_x >= x_min) && (root_x <= x_max) &&
                    246:                            (root_y >= y_min) && (root_y <= y_max))
                    247:                    {
                    248:                        largeur = ts[i].width;
                    249:                        hauteur = ts[i].height;
                    250:                        offset_x = ts[i].x_org;
                    251:                        offset_y = ts[i].y_org;
                    252: 
                    253:                        mouse_found = True;
                    254:                        break;
                    255:                    }
                    256:                }
                    257: 
                    258:                if (mouse_found == False)
                    259:                {
                    260:                    // Aucune souris sur un écran physique.
                    261: 
                    262:                    largeur = ts[0].width;
                    263:                    hauteur = ts[0].height;
                    264:                    offset_x = 0;
                    265:                    offset_y = 0;
                    266:                }
                    267:            }
                    268:            else
                    269:            {
                    270:                // Aucune souris, on considère le premier écran physique
                    271:                // géré par Xinerama.
                    272: 
                    273:                largeur = ts[0].width;
                    274:                hauteur = ts[0].height;
                    275:                offset_x = 0;
                    276:                offset_y = 0;
                    277:            }
                    278: 
                    279:            sys_free(root_windows);
                    280:            XFree(ts);
                    281:        }
                    282:        else
                    283:        {
                    284:            // Xinerama inactif, on considère qu'il n'y a qu'un seul
                    285:            // écran physique.
                    286:    
                    287:            largeur = WidthOfScreen(XtScreen(form));
                    288:            hauteur = HeightOfScreen(XtScreen(form));
                    289:            offset_x = 0;
                    290:            offset_y = 0;
                    291:        }
1.65    ! bertrand  292: uprintf("2\n");
1.61      bertrand  293: 
1.1       bertrand  294: #if 0
                    295:        XtRealizeWidget(objet_principal);
                    296: 
                    297:        XtVaGetValues(objet_principal,
                    298:                XmNheight, &hauteur_popup,
                    299:                XmNwidth, &largeur_popup,
                    300:                NULL);
                    301: 
                    302:        XtVaSetValues(objet_principal,
1.61      bertrand  303:                XmNx, offset_x + ((largeur - largeur_popup) / 2),
                    304:                XmNy, offset_y + ((hauteur - hauteur_popup) / 2),
1.1       bertrand  305:                NULL);
                    306: #else
                    307:        sscanf(rpl_xpm[0], "%d %d", &largeur_xpm, &hauteur_xpm);
                    308: 
1.42      bertrand  309:        largeur_popup = (Position) (largeur_xpm + 28);
                    310:        hauteur_popup = (Position) (hauteur_xpm + 28);
1.1       bertrand  311: 
                    312:        XtVaSetValues(objet_principal,
1.61      bertrand  313:                XmNx, offset_x + ((largeur - largeur_popup) / 2),
                    314:                XmNy, offset_y + ((hauteur - hauteur_popup) / 2),
1.1       bertrand  315:                NULL);
                    316: 
                    317:        XtRealizeWidget(objet_principal);
                    318: #endif
1.65    ! bertrand  319: uprintf("3\n");
1.1       bertrand  320: 
                    321:        XFlush(XtDisplay(form));
1.65    ! bertrand  322: uprintf("3a\n");
1.1       bertrand  323: 
                    324:        attente.tv_sec = 0;
                    325:        attente.tv_nsec = 1000;
                    326: 
                    327:        gettimeofday(&horodatage_initial, NULL);
                    328: 
                    329:        do
                    330:        {
1.65    ! bertrand  331: uprintf("3b\n");
1.1       bertrand  332:            if (XtAppPending(app) != 0)
                    333:            {
1.65    ! bertrand  334: uprintf("3c\n");
1.1       bertrand  335:                XtAppNextEvent(app, &evenement);
1.65    ! bertrand  336: uprintf("3d\n");
1.1       bertrand  337:                XtDispatchEvent(&evenement);
1.65    ! bertrand  338: uprintf("3e\n");
1.1       bertrand  339:            }
1.65    ! bertrand  340: uprintf("3f\n");
1.1       bertrand  341: 
                    342:            nanosleep(&attente, NULL);
                    343:            gettimeofday(&horodatage_final, NULL);
                    344: 
                    345:            temps_ecoule.tv_sec = horodatage_final.tv_sec
                    346:                    - horodatage_initial.tv_sec;
                    347:            temps_ecoule.tv_usec = horodatage_final.tv_usec
                    348:                    - horodatage_initial.tv_usec;
                    349: 
                    350:            if (temps_ecoule.tv_usec < 0)
                    351:            {
                    352:                temps_ecoule.tv_usec += 1000000;
                    353:                temps_ecoule.tv_sec--;
                    354:            }
1.42      bertrand  355:        } while (((((double) temps_ecoule.tv_usec) / ((double) 1000000))
                    356:                + ((double) temps_ecoule.tv_sec))
                    357:                < (((double) duree) / ((double) 1000000)));
1.1       bertrand  358: 
1.65    ! bertrand  359: uprintf("4\n");
1.1       bertrand  360:        XtUnrealizeWidget(objet_principal);
1.65    ! bertrand  361: uprintf("5\n");
1.1       bertrand  362: 
                    363:        while(XtAppPending(app) == 0)
                    364:        {
                    365:            nanosleep(&attente, NULL);
                    366:        }
                    367: 
                    368:        while(XtAppPending(app) != 0)
                    369:        {
                    370:            XtAppNextEvent(app, &evenement);
                    371:            XtDispatchEvent(&evenement);
                    372:            nanosleep(&attente, NULL);
                    373:        }
                    374: 
1.65    ! bertrand  375:        XtDestroyWidget(pixmap);
        !           376:        XtDestroyWidget(cadre);
        !           377:        XtDestroyWidget(form);
        !           378:        XtDestroyWidget(objet_principal);
        !           379: 
        !           380: uprintf("6\n");
1.64      bertrand  381:        XmDestroyPixmap(XtScreen(form), pixmap_rpl);
                    382:        XmDestroyPixmap(XtScreen(form), pixmap_rpl_masque);
                    383: 
1.62      bertrand  384:        XCloseDisplay(display);
                    385:        XtAppSetWarningHandler(app, old_message_handler);
1.1       bertrand  386:        XtDestroyApplicationContext(app);
1.65    ! bertrand  387: uprintf("7\n");
1.1       bertrand  388:    }
                    389: #  endif
                    390: 
                    391:    return;
                    392: }
                    393: 
                    394: // vim: ts=4

CVSweb interface <joel.bertrand@systella.fr>