Changeset dc5c303 in mainline for uspace/app/taskbar/taskbar.c


Ignore:
Timestamp:
2023-12-28T13:59:23Z (2 years ago)
Author:
GitHub <noreply@…>
Children:
6b66de6b
Parents:
42c2e65 (diff), f87ff8e (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
git-author:
boba-buba <120932204+boba-buba@…> (2023-12-28 13:59:23)
git-committer:
GitHub <noreply@…> (2023-12-28 13:59:23)
Message:

Merge branch 'master' into topic/packet-capture

File:
1 edited

Legend:

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

    r42c2e65 rdc5c303  
    11/*
    2  * Copyright (c) 2022 Jiri Svoboda
     2 * Copyright (c) 2023 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    3030 * @{
    3131 */
    32 /** @file Task Bar
     32/** @file Taskbar
    3333 */
    3434
     
    3939#include <str.h>
    4040#include <ui/fixed.h>
    41 #include <ui/label.h>
    4241#include <ui/resource.h>
    4342#include <ui/ui.h>
     
    4645#include "clock.h"
    4746#include "taskbar.h"
     47#include "tbsmenu.h"
    4848#include "wndlist.h"
    4949
    5050static void taskbar_wnd_close(ui_window_t *, void *);
     51static void taskbar_wnd_kbd(ui_window_t *, void *, kbd_event_t *);
    5152static void taskbar_wnd_pos(ui_window_t *, void *, pos_event_t *);
    5253
    5354static ui_window_cb_t window_cb = {
    5455        .close = taskbar_wnd_close,
     56        .kbd = taskbar_wnd_kbd,
    5557        .pos = taskbar_wnd_pos
    5658};
     
    6668
    6769        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 */
     78static 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        }
    6897}
    6998
     
    79108
    80109        /* Remember ID of device that sent the last event */
    81         taskbar->wndlist->ev_pos_id = event->pos_id;
     110        taskbar->wndlist->ev_idev_id = event->pos_id;
     111        taskbar->tbsmenu->ev_idev_id = event->pos_id;
    82112
    83113        ui_window_def_pos(window, event);
    84114}
    85115
    86 /** Create task bar.
     116/** Create taskbar.
    87117 *
    88118 * @param display_spec Display specification
    89119 * @param wndmgt_svc Window management service (or WNDMGT_DEFAULT)
    90  * @param rtaskbar Place to store pointer to new task bar
     120 * @param rtaskbar Place to store pointer to new taskbar
    91121 * @return @c EOK on success or an error coe
    92122 */
     
    98128        gfx_rect_t scr_rect;
    99129        gfx_rect_t rect;
    100         ui_resource_t *ui_res;
    101130        errno_t rc;
    102131
     
    128157
    129158        ui_wnd_params_init(&params);
    130         params.caption = "Task Bar";
     159        params.caption = "Taskbar";
    131160        params.placement = ui_wnd_place_bottom_left;
    132161
     
    160189        }
    161190
    162         ui_window_set_cb(taskbar->window, &window_cb, (void *)taskbar);
    163         ui_res = ui_window_get_res(taskbar->window);
    164 
    165191        rc = ui_fixed_create(&taskbar->fixed);
    166192        if (rc != EOK) {
     
    169195        }
    170196
    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);
     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
    178209        if (ui_is_textmode(taskbar->ui)) {
    179                 rect.p0.x += 1;
     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;
    180214        } 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         }
     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);
    193222
    194223        rc = wndlist_create(taskbar->window, taskbar->fixed, &taskbar->wndlist);
     
    199228
    200229        if (ui_is_textmode(taskbar->ui)) {
    201                 rect.p0.x = params.rect.p0.x + 9;
     230                rect.p0.x = params.rect.p0.x + 10;
    202231                rect.p0.y = 0;
    203232                rect.p1.x = params.rect.p1.x - 10;
     
    211240        wndlist_set_rect(taskbar->wndlist, &rect);
    212241
     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         */
    213246        rc = wndlist_open_wm(taskbar->wndlist, wndmgt_svc);
    214         if (rc != EOK) {
     247        if (rc != EOK && rc != ENOENT) {
    215248                printf("Error attaching window management service.\n");
    216249                goto error;
     
    243276
    244277        ui_window_add(taskbar->window, ui_fixed_ctl(taskbar->fixed));
     278        ui_window_set_cb(taskbar->window, &window_cb, (void *)taskbar);
    245279
    246280        rc = ui_window_paint(taskbar->window);
     
    257291        if (taskbar->wndlist != NULL)
    258292                wndlist_destroy(taskbar->wndlist);
     293        if (taskbar->tbsmenu != NULL)
     294                tbsmenu_destroy(taskbar->tbsmenu);
    259295        if (taskbar->window != NULL)
    260296                ui_window_destroy(taskbar->window);
     
    265301}
    266302
    267 /** Destroy task bar. */
     303/** Destroy taskbar. */
    268304void taskbar_destroy(taskbar_t *taskbar)
    269305{
    270306        ui_fixed_remove(taskbar->fixed, taskbar_clock_ctl(taskbar->clock));
    271307        taskbar_clock_destroy(taskbar->clock);
     308        wndlist_destroy(taskbar->wndlist);
     309        tbsmenu_destroy(taskbar->tbsmenu);
    272310        ui_window_destroy(taskbar->window);
    273311        ui_destroy(taskbar->ui);
Note: See TracChangeset for help on using the changeset viewer.