Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/viewer/viewer.c

    r2c7fdaa rc064b58  
    5151#define WINDOW_HEIGHT  768
    5252
     53#define DECORATION_WIDTH        8
     54#define DECORATION_HEIGHT       28
     55
    5356static size_t imgs_count;
    5457static size_t imgs_current = 0;
     
    5962static canvas_t *canvas = NULL;
    6063
    61 static bool img_load(const char *);
     64static surface_coord_t img_width;
     65static surface_coord_t img_height;
     66
     67static bool img_load(const char *, surface_t **);
     68static bool img_setup(surface_t *);
    6269
    6370static void on_keyboard_event(widget_t *widget, void *data)
     
    8895       
    8996        if (update) {
    90                 if (!img_load(imgs[imgs_current])) {
     97                surface_t *lsface;
     98
     99                if (!img_load(imgs[imgs_current], &lsface)) {
    91100                        printf("Cannot load image \"%s\".\n", imgs[imgs_current]);
    92                         exit(2);
    93                 }
    94         }
    95 }
    96 
    97 static bool img_load(const char *fname)
     101                        exit(4);
     102                }
     103                if (!img_setup(lsface)) {
     104                        printf("Cannot setup image \"%s\".\n", imgs[imgs_current]);
     105                        exit(6);
     106                }
     107        }
     108}
     109
     110static bool img_load(const char *fname, surface_t **p_local_surface)
    98111{
    99112        int fd = open(fname, O_RDONLY);
     
    103116        struct stat stat;
    104117        int rc = fstat(fd, &stat);
    105         if (rc != EOK) {
     118        if (rc != 0) {
    106119                close(fd);
    107120                return false;
     
    114127        }
    115128       
    116         ssize_t rd = read_all(fd, tga, stat.size);
     129        ssize_t rd = read(fd, tga, stat.size);
    117130        if ((rd < 0) || (rd != (ssize_t) stat.size)) {
    118131                free(tga);
     
    123136        close(fd);
    124137       
    125         surface_t *local_surface = decode_tga(tga, stat.size, 0);
    126         if (local_surface == NULL) {
     138        *p_local_surface = decode_tga(tga, stat.size, 0);
     139        if (*p_local_surface == NULL) {
    127140                free(tga);
    128141                return false;
     
    130143       
    131144        free(tga);
    132        
     145
     146        surface_get_resolution(*p_local_surface, &img_width, &img_height);
     147       
     148        return true;
     149}
     150
     151static bool img_setup(surface_t *local_surface)
     152{
    133153        if (canvas != NULL) {
    134154                if (!update_canvas(canvas, local_surface)) {
     
    138158        } else {
    139159                canvas = create_canvas(window_root(main_window),
    140                     WINDOW_WIDTH, WINDOW_HEIGHT, local_surface);
     160                    img_width, img_height, local_surface);
    141161                if (canvas == NULL) {
    142162                        surface_destroy(local_surface);
     
    151171       
    152172        surface = local_surface;
    153        
    154173        return true;
    155174}
     
    157176int main(int argc, char *argv[])
    158177{
     178        window_flags_t flags;
     179        surface_t *lsface;
     180        bool fullscreen;
     181        sysarg_t dwidth;
     182        sysarg_t dheight;
     183
    159184        if (argc < 2) {
    160185                printf("Compositor server not specified.\n");
     
    166191                return 1;
    167192        }
    168        
    169         main_window = window_open(argv[1], WINDOW_MAIN, "viewer");
    170         if (!main_window) {
    171                 printf("Cannot open main window.\n");
    172                 return 2;
    173         }
    174        
     193
    175194        imgs_count = argc - 2;
    176195        imgs = calloc(imgs_count, sizeof(char *));
    177196        if (imgs == NULL) {
    178197                printf("Out of memory.\n");
    179                 return 3;
     198                return 2;
    180199        }
    181200       
     
    184203                if (imgs[i] == NULL) {
    185204                        printf("Out of memory.\n");
    186                         return 4;
    187                 }
    188         }
    189        
    190         if (!img_load(imgs[imgs_current])) {
     205                        return 3;
     206                }
     207        }
     208
     209        if (!img_load(imgs[imgs_current], &lsface)) {
    191210                printf("Cannot load image \"%s\".\n", imgs[imgs_current]);
    192                 return 2;
    193         }
    194        
    195         window_resize(main_window, 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT,
    196             WINDOW_PLACEMENT_ABSOLUTE);
     211                return 4;
     212        }
     213
     214        fullscreen = ((img_width == WINDOW_WIDTH) &&
     215            (img_height == WINDOW_HEIGHT));
     216
     217        flags = WINDOW_MAIN;
     218        if (!fullscreen)
     219                flags |= WINDOW_DECORATED;
     220
     221        main_window = window_open(argv[1], flags, "viewer");
     222        if (!main_window) {
     223                printf("Cannot open main window.\n");
     224                return 5;
     225        }
     226       
     227       
     228        if (!img_setup(lsface)) {
     229                printf("Cannot setup image \"%s\".\n", imgs[imgs_current]);
     230                return 6;
     231        }
     232
     233        if (!fullscreen) {
     234                dwidth = DECORATION_WIDTH;
     235                dheight = DECORATION_HEIGHT;
     236        } else {
     237                dwidth = 0;
     238                dheight = 0;
     239        }
     240
     241        window_resize(main_window, 0, 0, img_width + dwidth,
     242            img_height + dheight, WINDOW_PLACEMENT_ANY);
    197243        window_exec(main_window);
    198244       
Note: See TracChangeset for help on using the changeset viewer.