Ignore:
File:
1 edited

Legend:

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

    r10cb47e r2c7fdaa  
    5151#define WINDOW_HEIGHT  768
    5252
    53 #define DECORATION_WIDTH        8
    54 #define DECORATION_HEIGHT       28
    55 
    5653static size_t imgs_count;
    5754static size_t imgs_current = 0;
     
    6259static canvas_t *canvas = NULL;
    6360
    64 static surface_coord_t img_width;
    65 static surface_coord_t img_height;
    66 
    67 static bool img_load(const char *, surface_t **);
    68 static bool img_setup(surface_t *);
     61static bool img_load(const char *);
    6962
    7063static void on_keyboard_event(widget_t *widget, void *data)
     
    9588       
    9689        if (update) {
    97                 surface_t *lsface;
    98 
    99                 if (!img_load(imgs[imgs_current], &lsface)) {
     90                if (!img_load(imgs[imgs_current])) {
    10091                        printf("Cannot load image \"%s\".\n", imgs[imgs_current]);
    101                         exit(4);
    102                 }
    103                 if (!img_setup(lsface)) {
    104                         printf("Cannot setup image \"%s\".\n", imgs[imgs_current]);
    105                         exit(6);
     92                        exit(2);
    10693                }
    10794        }
    10895}
    10996
    110 static bool img_load(const char *fname, surface_t **p_local_surface)
     97static bool img_load(const char *fname)
    11198{
    11299        int fd = open(fname, O_RDONLY);
     
    116103        struct stat stat;
    117104        int rc = fstat(fd, &stat);
    118         if (rc != 0) {
     105        if (rc != EOK) {
    119106                close(fd);
    120107                return false;
     
    127114        }
    128115       
    129         ssize_t rd = read(fd, tga, stat.size);
     116        ssize_t rd = read_all(fd, tga, stat.size);
    130117        if ((rd < 0) || (rd != (ssize_t) stat.size)) {
    131118                free(tga);
     
    136123        close(fd);
    137124       
    138         *p_local_surface = decode_tga(tga, stat.size, 0);
    139         if (*p_local_surface == NULL) {
     125        surface_t *local_surface = decode_tga(tga, stat.size, 0);
     126        if (local_surface == NULL) {
    140127                free(tga);
    141128                return false;
     
    143130       
    144131        free(tga);
    145 
    146         surface_get_resolution(*p_local_surface, &img_width, &img_height);
    147        
    148         return true;
    149 }
    150 
    151 static bool img_setup(surface_t *local_surface)
    152 {
     132       
    153133        if (canvas != NULL) {
    154134                if (!update_canvas(canvas, local_surface)) {
     
    157137                }
    158138        } else {
    159                 canvas = create_canvas(window_root(main_window), NULL,
    160                     img_width, img_height, local_surface);
     139                canvas = create_canvas(window_root(main_window),
     140                    WINDOW_WIDTH, WINDOW_HEIGHT, local_surface);
    161141                if (canvas == NULL) {
    162142                        surface_destroy(local_surface);
     
    171151       
    172152        surface = local_surface;
     153       
    173154        return true;
    174155}
     
    176157int main(int argc, char *argv[])
    177158{
    178         window_flags_t flags;
    179         surface_t *lsface;
    180         bool fullscreen;
    181         sysarg_t dwidth;
    182         sysarg_t dheight;
    183 
    184159        if (argc < 2) {
    185160                printf("Compositor server not specified.\n");
     
    191166                return 1;
    192167        }
    193 
     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       
    194175        imgs_count = argc - 2;
    195176        imgs = calloc(imgs_count, sizeof(char *));
    196177        if (imgs == NULL) {
    197178                printf("Out of memory.\n");
    198                 return 2;
     179                return 3;
    199180        }
    200181       
     
    203184                if (imgs[i] == NULL) {
    204185                        printf("Out of memory.\n");
    205                         return 3;
    206                 }
    207         }
    208 
    209         if (!img_load(imgs[imgs_current], &lsface)) {
     186                        return 4;
     187                }
     188        }
     189       
     190        if (!img_load(imgs[imgs_current])) {
    210191                printf("Cannot load image \"%s\".\n", imgs[imgs_current]);
    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], NULL, 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);
     192                return 2;
     193        }
     194       
     195        window_resize(main_window, 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT,
     196            WINDOW_PLACEMENT_ABSOLUTE);
    243197        window_exec(main_window);
    244198       
Note: See TracChangeset for help on using the changeset viewer.