Changeset bb65ccb3 in mainline
- Timestamp:
- 2023-04-14T13:05:15Z (21 months ago)
- Children:
- 00ef082
- Parents:
- 4bfb5a0
- git-author:
- SimonJRiddix <69309548+simonjriddix@…> (2023-04-14 13:05:15)
- git-committer:
- GitHub <noreply@…> (2023-04-14 13:05:15)
- Location:
- uspace/app/taskbar
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/taskbar/clock.c
r4bfb5a0 rbb65ccb3 61 61 }; 62 62 63 ClockFormat function_clock_format = american_clock_format; 64 65 usec_t clock_refresh_seconds = 5 * 1000 * 1000; 66 bool use_seconds = false; 67 bool italian_format = true; 68 69 void american_clock_format(struct tm time, char *buf, size_t bsize) 70 { 71 if(time.tm_hour == 0) 72 snprintf(buf, bsize, "%02d:%02d PM", time.tm_hour, time.tm_min); 73 else if(time.tm_hour > 12) 74 snprintf(buf, bsize, "%02d:%02d PM", time.tm_hour % 12, time.tm_min); 75 else 76 snprintf(buf, bsize, "%02d:%02d AM", time.tm_hour, time.tm_min); 77 } 78 79 void american_seconds_clock_format(struct tm time, char *buf, size_t bsize) 80 { 81 if(time.tm_hour == 0) 82 snprintf(buf, bsize, "%02d:%02d:%02d PM", time.tm_hour, time.tm_min, time.tm_sec); 83 else if(time.tm_hour > 12) 84 snprintf(buf, bsize, "%02d:%02d:%02d PM", time.tm_hour % 12, time.tm_min, time.tm_sec); 85 else 86 snprintf(buf, bsize, "%02d:%02d:%02d AM", time.tm_hour, time.tm_min, time.tm_sec); 87 } 88 89 void italian_clock_format(struct tm time, char *buf, size_t bsize) 90 { 91 snprintf(buf, bsize, "%02d:%02d", time.tm_hour, time.tm_min); 92 } 93 94 void italian_seconds_clock_format(struct tm time, char *buf, size_t bsize) 95 { 96 snprintf(buf, bsize, "%02d:%02d:%02d", time.tm_hour, time.tm_min, time.tm_sec); 97 } 98 99 void set_clock_format(void) 100 { 101 if(italian_format) 102 { 103 function_clock_format = (use_seconds) ? italian_seconds_clock_format : italian_clock_format; 104 } 105 else 106 { 107 function_clock_format = (use_seconds) ? american_seconds_clock_format : american_clock_format; 108 } 109 } 110 63 111 /** Create task bar clock. 64 112 * … … 71 119 taskbar_clock_t *clock; 72 120 errno_t rc; 121 122 set_clock_format(); 73 123 74 124 clock = calloc(1, sizeof(taskbar_clock_t)); … … 91 141 fibril_mutex_initialize(&clock->lock); 92 142 fibril_condvar_initialize(&clock->timer_done_cv); 93 fibril_timer_set(clock->timer, 1000000, taskbar_clock_timer, clock);143 fibril_timer_set(clock->timer, clock_refresh_seconds, taskbar_clock_timer, clock); 94 144 95 145 clock->window = window; … … 136 186 { 137 187 struct timespec ts; 138 struct tm t m;188 struct tm time; 139 189 errno_t rc; 140 190 141 191 getrealtime(&ts); 142 rc = time_utc2tm(ts.tv_sec, &t m);192 rc = time_utc2tm(ts.tv_sec, &time); 143 193 if (rc != EOK) 144 194 return rc; 145 195 146 snprintf(buf, bsize, "%02d:%02d:%02d", tm.tm_hour, tm.tm_min,147 tm.tm_sec);196 function_clock_format(time, buf, bsize); 197 148 198 return EOK; 149 199 } … … 327 377 328 378 if (!clock->timer_cleanup) { 329 fibril_timer_set(clock->timer, 1000000, taskbar_clock_timer,379 fibril_timer_set(clock->timer, clock_refresh_seconds, taskbar_clock_timer, 330 380 clock); 331 381 } else { -
uspace/app/taskbar/clock.h
r4bfb5a0 rbb65ccb3 54 54 extern void taskbar_clock_set_rect(taskbar_clock_t *, gfx_rect_t *); 55 55 56 void american_clock_format(struct tm time, char *buf, size_t bsize); 57 void american_seconds_clock_format(struct tm time, char *buf, size_t bsize); 58 void italian_clock_format(struct tm time, char *buf, size_t bsize); 59 void italian_seconds_clock_format(struct tm time, char *buf, size_t bsize); 60 void set_clock_format(void); 61 62 typedef void (*ClockFormat)(struct tm, char *, size_t); 63 56 64 #endif 57 65 -
uspace/app/taskbar/taskbar.c
r4bfb5a0 rbb65ccb3 38 38 #include <stdlib.h> 39 39 #include <str.h> 40 #include <str_error.h> 40 41 #include <ui/fixed.h> 41 42 #include <ui/label.h> … … 47 48 #include "taskbar.h" 48 49 #include "wndlist.h" 50 #include <task.h> 51 52 #define NAME "taskbar" 53 54 static const char *display_spec = UI_DISPLAY_DEFAULT; 55 56 bool TaskLauncherIsOpen = false; 57 task_id_t TaskLauncherid; 49 58 50 59 static void taskbar_wnd_close(ui_window_t *, void *); … … 55 64 .pos = taskbar_wnd_pos 56 65 }; 66 67 static void buttonApps_clicked(ui_pbutton_t *, void *); 68 69 static ui_pbutton_cb_t buttonApps_cb = { 70 .clicked = buttonApps_clicked 71 }; 72 73 static int app_launchl(const char *, ...); 57 74 58 75 /** Window close button was clicked. … … 129 146 ui_wnd_params_init(¶ms); 130 147 params.caption = "Task Bar"; 131 params.placement = ui_wnd_place_bottom_left ;148 params.placement = ui_wnd_place_bottom_left_absolute; 132 149 133 150 /* Window has no titlebar */ … … 169 186 } 170 187 171 rc = ui_label_create(ui_res, "HelenOS", &taskbar->label); 172 if (rc != EOK) { 173 printf("Error creating label.\n"); 174 goto error; 175 } 188 rc = ui_pbutton_create(ui_res, "Apps", &taskbar->buttonApps); 189 if (rc != EOK) { 190 printf("Error creating Application Menu.\n"); 191 goto error; 192 } 193 194 ui_pbutton_set_cb(taskbar->buttonApps, &buttonApps_cb, NULL); 176 195 177 196 ui_window_get_app_rect(taskbar->window, &rect); 178 197 if (ui_is_textmode(taskbar->ui)) { 179 198 rect.p0.x += 1; 199 rect.p1.x = rect.p0.x + 71; 180 200 } else { 181 201 rect.p0.x += 10; 182 }183 ui_label_set_rect(taskbar->label, &rect);184 ui_ label_set_halign(taskbar->label, gfx_halign_left);185 ui_ label_set_valign(taskbar->label, gfx_valign_center);186 187 rc = ui_fixed_add(taskbar->fixed, ui_ label_ctl(taskbar->label));188 if (rc != EOK) { 189 printf("Error adding control to layout.\n");190 ui_ label_destroy(taskbar->label);202 rect.p1.x = rect.p0.x +70; 203 } 204 ui_pbutton_set_rect(taskbar->buttonApps, &rect); 205 ui_pbutton_set_default(taskbar->buttonApps, true); 206 207 rc = ui_fixed_add(taskbar->fixed, ui_pbutton_ctl(taskbar->buttonApps)); 208 if (rc != EOK) { 209 printf("Error adding Application Menu control to layout.\n"); 210 ui_pbutton_destroy(taskbar->buttonApps); 191 211 goto error; 192 212 } … … 274 294 } 275 295 296 /** Application Menu was clicked. 297 * 298 * @param pbutton Application Menu button 299 * @param arg Argument 300 */ 301 static void buttonApps_clicked(ui_pbutton_t *pbutton, void *arg) 302 { 303 //taskbar_t *taskbar = (taskbar_t *) arg; 304 305 if(!TaskLauncherIsOpen) 306 { 307 if(app_launchl("/app/appslauncher", NULL) == EOK) 308 { 309 /*if(ui_pbutton_set_caption(pbutton, "Close") != EOK) 310 printf("Error changing entry text.\n"); 311 ui_pbutton_paint(pbutton);*/ 312 } 313 else 314 { 315 printf("Can't open launcher.\n"); 316 //return; 317 } 318 } 319 else 320 { 321 if (task_kill(TaskLauncherid) == EOK) 322 { 323 /*if(ui_pbutton_set_caption(pbutton, "Apps") != EOK) 324 printf("Error changing entry text.\n"); 325 ui_pbutton_paint(pbutton);*/ 326 } 327 else 328 { 329 printf("Can't kill launcher.\n"); 330 } 331 } 332 333 TaskLauncherIsOpen = !TaskLauncherIsOpen; 334 } 335 336 static int app_launchl(const char *app, ...) 337 { 338 errno_t rc; 339 task_id_t id; 340 task_wait_t wait; 341 va_list ap; 342 const char *arg; 343 const char **argv; 344 const char **argp; 345 int cnt = 0; 346 int i; 347 348 va_start(ap, app); 349 do { 350 arg = va_arg(ap, const char *); 351 cnt++; 352 } while (arg != NULL); 353 va_end(ap); 354 355 argv = calloc(cnt + 4, sizeof(const char *)); 356 if (argv == NULL) 357 return -1; 358 359 task_exit_t texit; 360 int retval; 361 362 argp = argv; 363 *argp++ = app; 364 365 if (str_cmp(display_spec, UI_DISPLAY_DEFAULT) != 0) { 366 *argp++ = "-d"; 367 *argp++ = display_spec; 368 } 369 370 va_start(ap, app); 371 do { 372 arg = va_arg(ap, const char *); 373 *argp++ = arg; 374 } while (arg != NULL); 375 va_end(ap); 376 377 *argp++ = NULL; 378 379 printf("%s: Spawning %s", NAME, app); 380 for (i = 0; argv[i] != NULL; i++) { 381 printf(" %s", argv[i]); 382 } 383 printf("\n"); 384 385 rc = task_spawnv(&id, &wait, app, argv); 386 if (rc != EOK) { 387 TaskLauncherid = -1; 388 printf("%s: Error spawning %s (%s)\n", NAME, app, str_error(rc)); 389 return -1; 390 } 391 392 TaskLauncherid = id; 393 394 rc = task_wait(&wait, &texit, &retval); 395 if ((rc != EOK) || (texit != TASK_EXIT_NORMAL)) { 396 printf("%s: Error retrieving retval from %s (%s)\n", NAME, 397 app, str_error(rc)); 398 return -1; 399 } 400 401 return retval; 402 } 403 276 404 /** @} 277 405 */ -
uspace/app/taskbar/types/taskbar.h
r4bfb5a0 rbb65ccb3 39 39 #include <types/common.h> 40 40 #include <ui/fixed.h> 41 #include <ui/ label.h>41 #include <ui/pbutton.h> 42 42 #include <ui/ui.h> 43 43 #include <ui/window.h> … … 53 53 /** Fixed layout */ 54 54 ui_fixed_t *fixed; 55 ui_label_t *label; 55 /** Taskbar Application Menu */ 56 ui_pbutton_t *buttonApps; 56 57 /** Window list */ 57 58 wndlist_t *wndlist;
Note:
See TracChangeset
for help on using the changeset viewer.