Changeset 553


Ignore:
Timestamp:
Mar 8, 2006, 8:41:53 PM (15 years ago)
Author:
Sam Hocevar
Message:
  • Fixed async issues between the driver and libcaca when resizing windows, and simplified the handle_resize() API. Still can be polished.
Location:
libcaca/trunk
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • libcaca/trunk/caca/caca.c

    r551 r553  
    8080    kk->lastticks = 0;
    8181
     82    /* Mouse position */
    8283    kk->mouse.x = kk->qq->width / 2;
    8384    kk->mouse.y = kk->qq->height / 2;
    8485
    85     kk->resize = 0;
    86     kk->resize_event = 0;
     86    /* Resize events */
     87    kk->resize.resized = 0;
    8788
    8889    return kk;
  • libcaca/trunk/caca/caca_internals.h

    r551 r553  
    102102        unsigned int (* get_window_height) (caca_t *);
    103103        void (* display) (caca_t *);
    104         void (* handle_resize) (caca_t *, unsigned int *, unsigned int *);
     104        void (* handle_resize) (caca_t *);
    105105        unsigned int (* get_event) (caca_t *);
    106106    } drv;
     
    113113
    114114    /* Window resize handling */
    115     int resize;
    116     int resize_event;
     115    struct resize
     116    {
     117        int resized;   /* A resize event was requested */
     118        //int acked;     /* The event has been acknowledged by the user */
     119        unsigned w, h; /* Requested width and height */
     120    } resize;
    117121
    118122    /* Framerate handling */
  • libcaca/trunk/caca/driver_conio.c

    r550 r553  
    114114}
    115115
    116 static void conio_handle_resize(caca_t *kk, unsigned int *new_width,
    117                                             unsigned int *new_height)
     116static void conio_handle_resize(caca_t *kk)
    118117{
    119     *new_width = kk->qq->width;
    120     *new_height = kk->qq->height;
     118    /* We know nothing about our window */
     119    kk->resize.w = kk->qq->width;
     120    kk->resize.h = kk->qq->height;
    121121}
    122122
  • libcaca/trunk/caca/driver_gl.c

    r551 r553  
    7676    int window;
    7777    unsigned int width, height;
     78    unsigned int new_width, new_height;
    7879    float font_width, font_height;
    7980    float incx, incy;
    8081    int id[94];
    81     unsigned char resized, bit;
     82    unsigned char bit;
    8283    unsigned char mouse_changed, mouse_clicked;
    8384    unsigned int mouse_x, mouse_y;
     
    8687    unsigned char key;
    8788    int special_key;
    88     int new_width;
    89     int new_height;
    9089
    9190    float sw, sh;
     
    118117    kk->drv.p->height = kk->qq->height * kk->drv.p->font_height;
    119118
    120     kk->drv.p->resized = 0;
    121119    kk->drv.p->bit = 0;
    122120
     
    294292}
    295293
    296 static void gl_handle_resize(caca_t *kk, unsigned int *new_width,
    297                                          unsigned int *new_height)
     294static void gl_handle_resize(caca_t *kk)
    298295{
    299296    kk->drv.p->width = kk->drv.p->new_width;
    300297    kk->drv.p->height = kk->drv.p->new_height;
    301 
    302     *new_width = kk->drv.p->width / kk->drv.p->font_width;
    303     *new_height = (kk->drv.p->height / kk->drv.p->font_height) + 1;
    304298
    305299    glMatrixMode(GL_PROJECTION);
     
    318312    glutMainLoopEvent();
    319313
    320     if(kk->drv.p->resized && !kk->resize)
    321     {
    322         kk->resize = 1;
    323         kk->drv.p->resized = 0;
     314    if(kk->resize.resized)
    324315        return CACA_EVENT_RESIZE;
    325     }
    326316
    327317    if(kk->drv.p->mouse_changed)
     
    401391        kk->drv.p->new_height = h;
    402392
    403         kk->drv.p->resized = 1;
     393        kk->resize.w = w / kk->drv.p->font_width;
     394        kk->resize.h = (h / kk->drv.p->font_height) + 1;
     395
     396        kk->resize.resized = 1;
    404397    }
    405398    else
  • libcaca/trunk/caca/driver_ncurses.c

    r551 r553  
    200200}
    201201
    202 static void ncurses_handle_resize(caca_t *kk, unsigned int *new_width,
    203                                               unsigned int *new_height)
     202static void ncurses_handle_resize(caca_t *kk)
    204203{
    205204    struct winsize size;
    206205
    207     *new_width = kk->qq->width;
    208     *new_height = kk->qq->height;
    209 
    210206    if(ioctl(fileno(stdout), TIOCGWINSZ, &size) == 0)
    211207    {
    212         *new_width = size.ws_col;
    213         *new_height = size.ws_row;
     208        kk->resize.w = size.ws_col;
     209        kk->resize.h = size.ws_row;
    214210#if defined(HAVE_RESIZE_TERM)
    215         resize_term(*new_height, *new_width);
     211        resize_term(kk->resize.h, kk->resize.w);
    216212#else
    217         resizeterm(*new_height, *new_width);
     213        resizeterm(*kk->resize.h, *kk->resize.w);
    218214#endif
    219215        wrefresh(curscr);
    220     }
     216        return;
     217    }
     218
     219    /* Fallback */
     220    kk->resize.w = kk->qq->width;
     221    kk->resize.h = kk->qq->height;
    221222}
    222223
     
    225226    unsigned int event;
    226227    int intkey;
    227 
    228     if(kk->resize_event)
    229     {
    230         kk->resize_event = 0;
    231         kk->resize = 1;
    232         return CACA_EVENT_RESIZE;
    233     }
    234228
    235229    intkey = getch();
     
    411405static RETSIGTYPE sigwinch_handler(int sig)
    412406{
    413     sigwinch_kk->resize_event = 1;
     407    sigwinch_kk->resize.resized = 1;
    414408
    415409    signal(SIGWINCH, sigwinch_handler);;
  • libcaca/trunk/caca/driver_slang.c

    r551 r553  
    237237}
    238238
    239 static void slang_handle_resize(caca_t *kk, unsigned int *new_width,
    240                                             unsigned int *new_height)
     239static void slang_handle_resize(caca_t *kk)
    241240{
    242241    SLtt_get_screen_size();
    243     *new_width = SLtt_Screen_Cols;
    244     *new_height = SLtt_Screen_Rows;
    245 
    246     if(*new_width != kk->qq->width || *new_height != kk->qq->height)
     242    kk->resize.w = SLtt_Screen_Cols;
     243    kk->resize.h = SLtt_Screen_Rows;
     244
     245    if(kk->resize.w != kk->qq->width || kk->resize.h != kk->qq->height)
    247246        SLsmg_reinit_smg();
    248247}
     
    252251    unsigned int event;
    253252    int intkey;
    254 
    255     if(kk->resize_event)
    256     {
    257         kk->resize_event = 0;
    258         kk->resize = 1;
    259         return CACA_EVENT_RESIZE;
    260     }
    261253
    262254    if(!SLang_input_pending(0))
     
    380372static RETSIGTYPE sigwinch_handler(int sig)
    381373{
    382     sigwinch_kk->resize_event = 1;
     374    sigwinch_kk->resize.resized = 1;
    383375
    384376    signal(SIGWINCH, sigwinch_handler);;
  • libcaca/trunk/caca/driver_win32.c

    r551 r553  
    215215}
    216216
    217 static void win32_handle_resize(caca_t *kk, unsigned int *new_width,
    218                                             unsigned int *new_height)
    219 {
    220     /* Nothing to do here. */
    221     *new_width = kk->qq->width;
    222     *new_height = kk->qq->height;
     217static void win32_handle_resize(caca_t *kk)
     218{
     219    /* FIXME: I don't know what to do here. */
     220    kk->resize.w = kk->qq->width;
     221    kk->resize.h = kk->qq->height;
    223222}
    224223
  • libcaca/trunk/caca/driver_x11.c

    r551 r553  
    5050    long int event_mask;
    5151    int font_width, font_height;
    52     unsigned int new_width, new_height;
    5352    int colors[16];
    5453    Font font;
     
    207206                                            DefaultScreen(kk->drv.p->dpy)));
    208207
    209     kk->drv.p->new_width = kk->drv.p->new_height = 0;
    210 
    211208    return 0;
    212209}
     
    311308}
    312309
    313 static void x11_handle_resize(caca_t *kk, unsigned int *new_width,
    314                                           unsigned int *new_height)
     310static void x11_handle_resize(caca_t *kk)
    315311{
    316312    Pixmap new_pixmap;
    317313
    318     *new_width = kk->drv.p->new_width;
    319     *new_height = kk->drv.p->new_height;
    320 
    321314    new_pixmap = XCreatePixmap(kk->drv.p->dpy, kk->drv.p->window,
    322                                kk->qq->width * kk->drv.p->font_width,
    323                                kk->qq->height * kk->drv.p->font_height,
     315                               kk->resize.w * kk->drv.p->font_width,
     316                               kk->resize.h * kk->drv.p->font_height,
    324317                               DefaultDepth(kk->drv.p->dpy,
    325318                                            DefaultScreen(kk->drv.p->dpy)));
    326     XCopyArea(kk->drv.p->dpy, kk->drv.p->pixmap, new_pixmap, kk->drv.p->gc, 0, 0,
    327               kk->qq->width * kk->drv.p->font_width,
    328               kk->qq->height * kk->drv.p->font_height, 0, 0);
     319    XCopyArea(kk->drv.p->dpy, kk->drv.p->pixmap, new_pixmap,
     320              kk->drv.p->gc, 0, 0,
     321              kk->resize.w * kk->drv.p->font_width,
     322              kk->resize.h * kk->drv.p->font_height, 0, 0);
    329323    XFreePixmap(kk->drv.p->dpy, kk->drv.p->pixmap);
    330324    kk->drv.p->pixmap = new_pixmap;
     
    365359                continue;
    366360
    367             kk->drv.p->new_width = w;
    368             kk->drv.p->new_height = h;
    369 
    370             /* If we are already resizing, ignore the new signal */
    371             if(kk->resize)
    372                 continue;
    373 
    374             kk->resize = 1;
    375 
    376             return CACA_EVENT_RESIZE;
     361            kk->resize.w = w;
     362            kk->resize.h = h;
     363            kk->resize.resized = 1;
     364
     365            continue;
    377366        }
    378367
  • libcaca/trunk/caca/event.c

    r551 r553  
    138138    unsigned int event;
    139139
     140    /* If we are about to return a resize event, acknowledge it */
     141    if(kk->resize.resized)
     142    {
     143        kk->resize.resized = 0;
     144        _caca_handle_resize(kk);
     145        return CACA_EVENT_RESIZE;
     146    }
     147
    140148    event = _lowlevel_event(kk);
    141149
  • libcaca/trunk/caca/graphics.c

    r550 r553  
    3636 * Local functions
    3737 */
    38 static void caca_handle_resize(caca_t *kk);
     38void _caca_handle_resize(caca_t *kk);
    3939
    4040/** \brief Set the window title.
     
    131131    kk->drv.display(kk);
    132132
    133     /* FIXME handle this somewhere else */
    134     if(kk->resize)
     133    /* Once the display is finished, we can ack resizes */
     134    if(kk->resize.resized)
    135135    {
    136         kk->resize = 0;
    137         caca_handle_resize(kk);
     136        kk->resize.resized = 0;
     137        _caca_handle_resize(kk);
    138138    }
    139139
     
    161161 */
    162162
    163 static void caca_handle_resize(caca_t *kk)
     163void _caca_handle_resize(caca_t *kk)
    164164{
    165     unsigned int new_width, new_height;
    166 
    167     kk->drv.handle_resize(kk, &new_width, &new_height);
     165    kk->drv.handle_resize(kk);
    168166
    169167    /* Tell libcucul we changed size */
    170     if(new_width != kk->qq->width || new_height != kk->qq->height)
    171         cucul_set_size(kk->qq, new_width, new_height);
     168    if(kk->resize.w != kk->qq->width || kk->resize.h != kk->qq->height)
     169        _cucul_set_size(kk->qq, kk->resize.w, kk->resize.h);
    172170}
    173171
  • libcaca/trunk/cucul/cucul.c

    r552 r553  
    9797        return;
    9898
    99     cucul_set_size_internal(qq, width, height);
     99    _cucul_set_size(qq, width, height);
    100100}
    101101
Note: See TracChangeset for help on using the changeset viewer.