Changes in uspace/app/viewer/viewer.c [10cb47e:2c7fdaa] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/viewer/viewer.c
r10cb47e r2c7fdaa 51 51 #define WINDOW_HEIGHT 768 52 52 53 #define DECORATION_WIDTH 854 #define DECORATION_HEIGHT 2855 56 53 static size_t imgs_count; 57 54 static size_t imgs_current = 0; … … 62 59 static canvas_t *canvas = NULL; 63 60 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 *); 61 static bool img_load(const char *); 69 62 70 63 static void on_keyboard_event(widget_t *widget, void *data) … … 95 88 96 89 if (update) { 97 surface_t *lsface; 98 99 if (!img_load(imgs[imgs_current], &lsface)) { 90 if (!img_load(imgs[imgs_current])) { 100 91 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); 106 93 } 107 94 } 108 95 } 109 96 110 static bool img_load(const char *fname , surface_t **p_local_surface)97 static bool img_load(const char *fname) 111 98 { 112 99 int fd = open(fname, O_RDONLY); … … 116 103 struct stat stat; 117 104 int rc = fstat(fd, &stat); 118 if (rc != 0) {105 if (rc != EOK) { 119 106 close(fd); 120 107 return false; … … 127 114 } 128 115 129 ssize_t rd = read (fd, tga, stat.size);116 ssize_t rd = read_all(fd, tga, stat.size); 130 117 if ((rd < 0) || (rd != (ssize_t) stat.size)) { 131 118 free(tga); … … 136 123 close(fd); 137 124 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) { 140 127 free(tga); 141 128 return false; … … 143 130 144 131 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 153 133 if (canvas != NULL) { 154 134 if (!update_canvas(canvas, local_surface)) { … … 157 137 } 158 138 } 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); 161 141 if (canvas == NULL) { 162 142 surface_destroy(local_surface); … … 171 151 172 152 surface = local_surface; 153 173 154 return true; 174 155 } … … 176 157 int main(int argc, char *argv[]) 177 158 { 178 window_flags_t flags;179 surface_t *lsface;180 bool fullscreen;181 sysarg_t dwidth;182 sysarg_t dheight;183 184 159 if (argc < 2) { 185 160 printf("Compositor server not specified.\n"); … … 191 166 return 1; 192 167 } 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 194 175 imgs_count = argc - 2; 195 176 imgs = calloc(imgs_count, sizeof(char *)); 196 177 if (imgs == NULL) { 197 178 printf("Out of memory.\n"); 198 return 2;179 return 3; 199 180 } 200 181 … … 203 184 if (imgs[i] == NULL) { 204 185 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])) { 210 191 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); 243 197 window_exec(main_window); 244 198
Note:
See TracChangeset
for help on using the changeset viewer.