Ignore:
File:
1 edited

Legend:

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

    r82d3c28 r29a5a99  
    11/*
    2  * Copyright (c) 2023 Jiri Svoboda
     2 * Copyright (c) 2022 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    3030 * @{
    3131 */
    32 /** @file Taskbar
     32/** @file Task Bar
    3333 */
    3434
     
    3939#include <str.h>
    4040#include <ui/fixed.h>
     41#include <ui/label.h>
    4142#include <ui/resource.h>
    4243#include <ui/ui.h>
     
    4546#include "clock.h"
    4647#include "taskbar.h"
    47 #include "tbsmenu.h"
    4848#include "wndlist.h"
    4949
    5050static void taskbar_wnd_close(ui_window_t *, void *);
    51 static void taskbar_wnd_kbd(ui_window_t *, void *, kbd_event_t *);
    5251static void taskbar_wnd_pos(ui_window_t *, void *, pos_event_t *);
    5352
    5453static ui_window_cb_t window_cb = {
    5554        .close = taskbar_wnd_close,
    56         .kbd = taskbar_wnd_kbd,
    5755        .pos = taskbar_wnd_pos
    5856};
     
    6866
    6967        ui_quit(taskbar->ui);
    70 }
    71 
    72 /** Window received keyboard event.
    73  *
    74  * @param window Window
    75  * @param arg Argument (taskbar)
    76  * @param event Keyboard event
    77  */
    78 static void taskbar_wnd_kbd(ui_window_t *window, void *arg, kbd_event_t *event)
    79 {
    80         taskbar_t *taskbar = (taskbar_t *) arg;
    81         ui_evclaim_t claim;
    82 
    83         /* Remember ID of device that sent the last event */
    84         taskbar->wndlist->ev_idev_id = event->kbd_id;
    85         taskbar->tbsmenu->ev_idev_id = event->kbd_id;
    86 
    87         claim = ui_window_def_kbd(window, event);
    88         if (claim == ui_claimed)
    89                 return;
    90 
    91         if (event->type == KEY_PRESS && (event->mods & KM_CTRL) == 0 &&
    92             (event->mods & KM_ALT) == 0 && (event->mods & KM_SHIFT) == 0 &&
    93             event->key == KC_ENTER) {
    94                 if (!tbsmenu_is_open(taskbar->tbsmenu))
    95                         tbsmenu_open(taskbar->tbsmenu);
    96         }
    9768}
    9869
     
    10879
    10980        /* Remember ID of device that sent the last event */
    110         taskbar->wndlist->ev_idev_id = event->pos_id;
    111         taskbar->tbsmenu->ev_idev_id = event->pos_id;
     81        taskbar->wndlist->ev_pos_id = event->pos_id;
    11282
    11383        ui_window_def_pos(window, event);
    11484}
    11585
    116 /** Create taskbar.
     86/** Create task bar.
    11787 *
    11888 * @param display_spec Display specification
    11989 * @param wndmgt_svc Window management service (or WNDMGT_DEFAULT)
    120  * @param rtaskbar Place to store pointer to new taskbar
     90 * @param rtaskbar Place to store pointer to new task bar
    12191 * @return @c EOK on success or an error coe
    12292 */
     
    12898        gfx_rect_t scr_rect;
    12999        gfx_rect_t rect;
     100        ui_resource_t *ui_res;
    130101        errno_t rc;
    131102
     
    157128
    158129        ui_wnd_params_init(&params);
    159         params.caption = "Taskbar";
     130        params.caption = "Task Bar";
    160131        params.placement = ui_wnd_place_bottom_left;
    161132
     
    189160        }
    190161
     162        ui_window_set_cb(taskbar->window, &window_cb, (void *)taskbar);
     163        ui_res = ui_window_get_res(taskbar->window);
     164
    191165        rc = ui_fixed_create(&taskbar->fixed);
    192166        if (rc != EOK) {
     
    195169        }
    196170
    197         rc = tbsmenu_create(taskbar->window, taskbar->fixed, &taskbar->tbsmenu);
    198         if (rc != EOK) {
    199                 printf("Error creating start menu.\n");
    200                 goto error;
    201         }
    202 
    203         rc = tbsmenu_load(taskbar->tbsmenu, "/cfg/taskbar.sif");
    204         if (rc != EOK) {
    205                 printf("Error loading start menu from '%s'.\n",
    206                     "/cfg/taskbar.sif");
    207         }
    208 
    209         if (ui_is_textmode(taskbar->ui)) {
    210                 rect.p0.x = params.rect.p0.x + 1;
    211                 rect.p0.y = 0;
    212                 rect.p1.x = params.rect.p0.x + 9;
    213                 rect.p1.y = 1;
    214         } else {
    215                 rect.p0.x = params.rect.p0.x + 5;
    216                 rect.p0.y = 4;
    217                 rect.p1.x = params.rect.p0.x + 84;
    218                 rect.p1.y = 32 - 4;
    219         }
    220 
    221         tbsmenu_set_rect(taskbar->tbsmenu, &rect);
     171        rc = ui_label_create(ui_res, "HelenOS", &taskbar->label);
     172        if (rc != EOK) {
     173                printf("Error creating label.\n");
     174                goto error;
     175        }
     176
     177        ui_window_get_app_rect(taskbar->window, &rect);
     178        if (ui_is_textmode(taskbar->ui)) {
     179                rect.p0.x += 1;
     180        } else {
     181                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);
     191                goto error;
     192        }
    222193
    223194        rc = wndlist_create(taskbar->window, taskbar->fixed, &taskbar->wndlist);
     
    228199
    229200        if (ui_is_textmode(taskbar->ui)) {
    230                 rect.p0.x = params.rect.p0.x + 10;
     201                rect.p0.x = params.rect.p0.x + 9;
    231202                rect.p0.y = 0;
    232203                rect.p1.x = params.rect.p1.x - 10;
     
    240211        wndlist_set_rect(taskbar->wndlist, &rect);
    241212
    242         /*
    243          * We may not be able to open WM service if display server is not
    244          * running. That's okay, there simply are no windows to manage.
    245          */
    246213        rc = wndlist_open_wm(taskbar->wndlist, wndmgt_svc);
    247         if (rc != EOK && rc != ENOENT) {
     214        if (rc != EOK) {
    248215                printf("Error attaching window management service.\n");
    249216                goto error;
     
    276243
    277244        ui_window_add(taskbar->window, ui_fixed_ctl(taskbar->fixed));
    278         ui_window_set_cb(taskbar->window, &window_cb, (void *)taskbar);
    279245
    280246        rc = ui_window_paint(taskbar->window);
     
    291257        if (taskbar->wndlist != NULL)
    292258                wndlist_destroy(taskbar->wndlist);
    293         if (taskbar->tbsmenu != NULL)
    294                 tbsmenu_destroy(taskbar->tbsmenu);
    295259        if (taskbar->window != NULL)
    296260                ui_window_destroy(taskbar->window);
     
    301265}
    302266
    303 /** Destroy taskbar. */
     267/** Destroy task bar. */
    304268void taskbar_destroy(taskbar_t *taskbar)
    305269{
    306270        ui_fixed_remove(taskbar->fixed, taskbar_clock_ctl(taskbar->clock));
    307271        taskbar_clock_destroy(taskbar->clock);
    308         wndlist_destroy(taskbar->wndlist);
    309         tbsmenu_destroy(taskbar->tbsmenu);
    310272        ui_window_destroy(taskbar->window);
    311273        ui_destroy(taskbar->ui);
Note: See TracChangeset for help on using the changeset viewer.