Changeset 62fbb7e in mainline for uspace/lib/gui/window.c


Ignore:
Timestamp:
2014-01-16T20:43:22Z (10 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
6a3d0c7
Parents:
ba02baa
Message:

refactor window placement logic and introduce logical window placement flags

  • The original setup of window position during creation (window_open()) was quite useless, because the window had no surface yet.
  • Now the window position can be optinally set using window_resize() and various logical placement flags are available.
  • A separate window_move() routine could be introduced eventually if needed, but for the initial setup of the window the combination of window position and size works fine.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/gui/window.c

    rba02baa r62fbb7e  
    352352}
    353353
    354 static void handle_signal_event(window_t *win, sig_event_t event)
     354static void handle_signal_event(window_t *win, signal_event_t event)
    355355{
    356356        widget_t *widget = (widget_t *) event.object;
     
    363363}
    364364
    365 static void handle_resize(window_t *win, sysarg_t width, sysarg_t height)
    366 {
    367         int rc;
    368         surface_t *old_surface;
    369         surface_t *new_surface;
    370 
     365static void handle_resize(window_t *win, sysarg_t offset_x, sysarg_t offset_y,
     366    sysarg_t width, sysarg_t height, window_placement_flags_t placement_flags)
     367{
    371368        if (width < 2 * border_thickness + header_min_width) {
    372369                win_damage(win->osess, 0, 0, 0, 0);
    373370                return;
    374371        }
    375 
     372       
    376373        if (height < 2 * border_thickness + header_height) {
    377374                win_damage(win->osess, 0, 0, 0, 0);
    378375                return;
    379376        }
    380 
     377       
    381378        /* Allocate resources for new surface. */
    382         new_surface = surface_create(width, height, NULL, SURFACE_FLAG_SHARED);
    383         if (!new_surface) {
     379        surface_t *new_surface = surface_create(width, height, NULL,
     380            SURFACE_FLAG_SHARED);
     381        if (!new_surface)
    384382                return;
    385         }
    386 
     383       
    387384        /* Switch new and old surface. */
    388385        fibril_mutex_lock(&win->guard);
    389         old_surface = win->surface;
     386        surface_t *old_surface = win->surface;
    390387        win->surface = new_surface;
    391388        fibril_mutex_unlock(&win->guard);
    392 
    393         /* Let all widgets in the tree alter their position and size. Widgets might
    394          * also paint themselves onto the new surface. */
     389       
     390        /*
     391         * Let all widgets in the tree alter their position and size.
     392         * Widgets might also paint themselves onto the new surface.
     393         */
    395394        win->root.rearrange(&win->root, 0, 0, width, height);
    396 
     395       
    397396        fibril_mutex_lock(&win->guard);
    398397        surface_reset_damaged_region(win->surface);
    399398        fibril_mutex_unlock(&win->guard);
    400 
     399       
    401400        /* Inform compositor about new surface. */
    402         rc = win_resize(win->osess,
    403                 width, height, surface_direct_access(new_surface));
    404 
     401        int rc = win_resize(win->osess, offset_x, offset_y, width, height,
     402            placement_flags, surface_direct_access(new_surface));
     403       
    405404        if (rc != EOK) {
    406405                /* Rollback to old surface. Reverse all changes. */
    407 
     406               
    408407                sysarg_t old_width = 0;
    409408                sysarg_t old_height = 0;
    410                 if (old_surface) {
     409                if (old_surface)
    411410                        surface_get_resolution(old_surface, &old_width, &old_height);
    412                 }
    413 
     411               
    414412                fibril_mutex_lock(&win->guard);
    415413                new_surface = win->surface;
    416414                win->surface = old_surface;
    417415                fibril_mutex_unlock(&win->guard);
    418 
     416               
    419417                win->root.rearrange(&win->root, 0, 0, old_width, old_height);
    420418               
     
    424422                        fibril_mutex_unlock(&win->guard);
    425423                }
    426 
     424               
    427425                surface_destroy(new_surface);
    428                 return;
    429         }
    430 
    431         /* Finally deallocate old surface. */
    432         if (old_surface) {
    433                 surface_destroy(old_surface);
     426        } else {
     427                /* Deallocate old surface. */
     428                if (old_surface)
     429                        surface_destroy(old_surface);
    434430        }
    435431}
     
    513509                        break;
    514510                case ET_SIGNAL_EVENT:
    515                         handle_signal_event(win, event->data.sig);
     511                        handle_signal_event(win, event->data.signal);
    516512                        break;
    517513                case ET_WINDOW_RESIZE:
    518                         handle_resize(win, event->data.rsz.width, event->data.rsz.height);
     514                        handle_resize(win, event->data.resize.offset_x,
     515                            event->data.resize.offset_y, event->data.resize.width,
     516                            event->data.resize.height, event->data.resize.placement_flags);
    519517                        break;
    520518                case ET_WINDOW_FOCUS:
     
    590588
    591589window_t *window_open(const char *winreg, bool is_main, bool is_decorated,
    592     const char *caption, sysarg_t x_offset, sysarg_t y_offset)
     590    const char *caption)
    593591{
    594592        window_t *win = (window_t *) malloc(sizeof(window_t));
     
    630628        service_id_t in_dsid;
    631629        service_id_t out_dsid;
    632         rc = win_register(reg_sess, &in_dsid, &out_dsid, x_offset, y_offset);
     630        rc = win_register(reg_sess, &in_dsid, &out_dsid);
    633631        async_hangup(reg_sess);
    634632        if (rc != EOK) {
     
    658656}
    659657
    660 void window_resize(window_t *win, sysarg_t width, sysarg_t height)
     658void window_resize(window_t *win, sysarg_t offset_x, sysarg_t offset_y,
     659    sysarg_t width, sysarg_t height, window_placement_flags_t placement_flags)
    661660{
    662661        window_event_t *event = (window_event_t *) malloc(sizeof(window_event_t));
     
    664663                link_initialize(&event->link);
    665664                event->type = ET_WINDOW_RESIZE;
    666                 event->data.rsz.width = width;
    667                 event->data.rsz.height = height;
     665                event->data.resize.offset_x = offset_x;
     666                event->data.resize.offset_y = offset_y;
     667                event->data.resize.width = width;
     668                event->data.resize.height = height;
     669                event->data.resize.placement_flags = placement_flags;
    668670                prodcons_produce(&win->events, &event->link);
    669671        }
Note: See TracChangeset for help on using the changeset viewer.