source: mainline/uspace/app/taskbar/taskbar.c@ 2139676

ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 2139676 was 2139676, checked in by Jiri Svoboda <jiri@…>, 3 years ago

Add initial task bar application

  • Property mode set to 100644
File size: 4.4 KB
Line 
1/*
2 * Copyright (c) 2022 Jiri Svoboda
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup taskbar
30 * @{
31 */
32/** @file Task Bar
33 */
34
35#include <gfx/coord.h>
36#include <stdio.h>
37#include <stdlib.h>
38#include <str.h>
39#include <ui/fixed.h>
40#include <ui/label.h>
41#include <ui/resource.h>
42#include <ui/ui.h>
43#include <ui/window.h>
44#include "taskbar.h"
45
46static void wnd_close(ui_window_t *, void *);
47
48static ui_window_cb_t window_cb = {
49 .close = wnd_close
50};
51
52/** Window close button was clicked.
53 *
54 * @param window Window
55 * @param arg Argument (taskbar)
56 */
57static void wnd_close(ui_window_t *window, void *arg)
58{
59 taskbar_t *taskbar = (taskbar_t *) arg;
60
61 ui_quit(taskbar->ui);
62}
63
64/** Create task bar.
65 *
66 * @param display_spec Display specification
67 * @param rtaskbar Place to store pointer to new task bar
68 * @return @c EOK on success or an error coe
69 */
70errno_t taskbar_create(const char *display_spec, taskbar_t **rtaskbar)
71{
72 ui_wnd_params_t params;
73 taskbar_t *taskbar = NULL;
74 gfx_rect_t rect;
75 ui_resource_t *ui_res;
76 errno_t rc;
77
78 taskbar = calloc(1, sizeof(taskbar_t));
79 if (taskbar == NULL) {
80 rc = ENOMEM;
81 goto error;
82 }
83
84 rc = ui_create(display_spec, &taskbar->ui);
85 if (rc != EOK) {
86 printf("Error creating UI on display %s.\n", display_spec);
87 goto error;
88 }
89
90 ui_wnd_params_init(&params);
91 params.caption = "Task Bar";
92 params.placement = ui_wnd_place_bottom_left;
93 params.style &= ~ui_wds_titlebar;
94
95 if (ui_is_textmode(taskbar->ui)) {
96 params.rect.p0.x = 0;
97 params.rect.p0.y = 0;
98 params.rect.p1.x = 24;
99 params.rect.p1.y = 5;
100 } else {
101 params.rect.p0.x = 0;
102 params.rect.p0.y = 0;
103 params.rect.p1.x = 1024;
104 params.rect.p1.y = 32;
105 }
106
107 rc = ui_window_create(taskbar->ui, &params, &taskbar->window);
108 if (rc != EOK) {
109 printf("Error creating window.\n");
110 goto error;
111 }
112
113 ui_window_set_cb(taskbar->window, &window_cb, (void *) &taskbar);
114 ui_res = ui_window_get_res(taskbar->window);
115
116 rc = ui_fixed_create(&taskbar->fixed);
117 if (rc != EOK) {
118 printf("Error creating fixed layout.\n");
119 goto error;
120 }
121
122 rc = ui_label_create(ui_res, "Task bar!", &taskbar->label);
123 if (rc != EOK) {
124 printf("Error creating label.\n");
125 goto error;
126 }
127
128 ui_window_get_app_rect(taskbar->window, &rect);
129 ui_label_set_rect(taskbar->label, &rect);
130 ui_label_set_halign(taskbar->label, gfx_halign_center);
131 ui_label_set_valign(taskbar->label, gfx_valign_center);
132
133 rc = ui_fixed_add(taskbar->fixed, ui_label_ctl(taskbar->label));
134 if (rc != EOK) {
135 printf("Error adding control to layout.\n");
136 ui_label_destroy(taskbar->label);
137 goto error;
138 }
139
140 ui_window_add(taskbar->window, ui_fixed_ctl(taskbar->fixed));
141
142 rc = ui_window_paint(taskbar->window);
143 if (rc != EOK) {
144 printf("Error painting window.\n");
145 goto error;
146 }
147
148 *rtaskbar = taskbar;
149 return EOK;
150error:
151 if (taskbar->window != NULL)
152 ui_window_destroy(taskbar->window);
153 if (taskbar->ui != NULL)
154 ui_destroy(taskbar->ui);
155 return rc;
156
157}
158
159/** Destroy task bar. */
160void taskbar_destroy(taskbar_t *taskbar)
161{
162 ui_window_destroy(taskbar->window);
163 ui_destroy(taskbar->ui);
164}
165
166/** @}
167 */
Note: See TracBrowser for help on using the repository browser.