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

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

Add window list to taskbar (with one dummy entry so far)

  • Property mode set to 100644
File size: 5.9 KB
RevLine 
[2139676]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>
[50a16d9]44#include "clock.h"
[2139676]45#include "taskbar.h"
[e0e612b]46#include "wndlist.h"
[2139676]47
48static void wnd_close(ui_window_t *, void *);
49
50static ui_window_cb_t window_cb = {
51 .close = wnd_close
52};
53
54/** Window close button was clicked.
55 *
56 * @param window Window
57 * @param arg Argument (taskbar)
58 */
59static void wnd_close(ui_window_t *window, void *arg)
60{
61 taskbar_t *taskbar = (taskbar_t *) arg;
62
63 ui_quit(taskbar->ui);
64}
65
66/** Create task bar.
67 *
68 * @param display_spec Display specification
69 * @param rtaskbar Place to store pointer to new task bar
70 * @return @c EOK on success or an error coe
71 */
72errno_t taskbar_create(const char *display_spec, taskbar_t **rtaskbar)
73{
74 ui_wnd_params_t params;
75 taskbar_t *taskbar = NULL;
[3fd38b2]76 gfx_rect_t scr_rect;
[2139676]77 gfx_rect_t rect;
78 ui_resource_t *ui_res;
79 errno_t rc;
80
81 taskbar = calloc(1, sizeof(taskbar_t));
82 if (taskbar == NULL) {
83 rc = ENOMEM;
84 goto error;
85 }
86
87 rc = ui_create(display_spec, &taskbar->ui);
88 if (rc != EOK) {
89 printf("Error creating UI on display %s.\n", display_spec);
90 goto error;
91 }
92
[3fd38b2]93 rc = ui_get_rect(taskbar->ui, &scr_rect);
94 if (rc != EOK) {
[c77cfd8]95 if (str_cmp(display_spec, UI_DISPLAY_NULL) != 0) {
96 printf("Error getting screen dimensions.\n");
97 goto error;
98 }
99
100 /* For the sake of unit tests */
101 scr_rect.p0.x = 0;
102 scr_rect.p0.y = 0;
103 scr_rect.p1.x = 100;
104 scr_rect.p1.y = 100;
[3fd38b2]105 }
106
[2139676]107 ui_wnd_params_init(&params);
108 params.caption = "Task Bar";
109 params.placement = ui_wnd_place_bottom_left;
110 params.style &= ~ui_wds_titlebar;
111
[3fd38b2]112 params.rect.p0.x = 0;
113 params.rect.p0.y = 0;
114 params.rect.p1.x = scr_rect.p1.x - scr_rect.p0.x;
115
[2139676]116 if (ui_is_textmode(taskbar->ui)) {
[50a16d9]117 params.rect.p1.y = 1;
118 params.style &= ~ui_wds_frame;
[2139676]119 } else {
120 params.rect.p1.y = 32;
121 }
122
123 rc = ui_window_create(taskbar->ui, &params, &taskbar->window);
124 if (rc != EOK) {
125 printf("Error creating window.\n");
126 goto error;
127 }
128
129 ui_window_set_cb(taskbar->window, &window_cb, (void *) &taskbar);
130 ui_res = ui_window_get_res(taskbar->window);
131
132 rc = ui_fixed_create(&taskbar->fixed);
133 if (rc != EOK) {
134 printf("Error creating fixed layout.\n");
135 goto error;
136 }
137
[e0e612b]138 rc = ui_label_create(ui_res, "HelenOS", &taskbar->label);
[2139676]139 if (rc != EOK) {
140 printf("Error creating label.\n");
141 goto error;
142 }
143
144 ui_window_get_app_rect(taskbar->window, &rect);
[e0e612b]145 if (ui_is_textmode(taskbar->ui)) {
146 rect.p0.x += 1;
147 } else {
148 rect.p0.x += 10;
149 }
[2139676]150 ui_label_set_rect(taskbar->label, &rect);
[e0e612b]151 ui_label_set_halign(taskbar->label, gfx_halign_left);
[2139676]152 ui_label_set_valign(taskbar->label, gfx_valign_center);
153
154 rc = ui_fixed_add(taskbar->fixed, ui_label_ctl(taskbar->label));
155 if (rc != EOK) {
156 printf("Error adding control to layout.\n");
157 ui_label_destroy(taskbar->label);
158 goto error;
159 }
160
[e0e612b]161 rc = wndlist_create(ui_res, taskbar->fixed, &taskbar->wndlist);
162 if (rc != EOK) {
163 printf("Error creating window list.\n");
164 goto error;
165 }
166
167 rc = wndlist_append(taskbar->wndlist, "Text Editor");
168 if (rc != EOK) {
169 printf("Error adding window list entry.\n");
170 goto error;
171 }
172
[50a16d9]173 rc = taskbar_clock_create(taskbar->window, &taskbar->clock);
174 if (rc != EOK)
175 goto error;
176
[3fd38b2]177 if (ui_is_textmode(taskbar->ui)) {
178 rect.p0.x = params.rect.p1.x - 10;
179 rect.p0.y = 0;
180 rect.p1.x = params.rect.p1.x;
181 rect.p1.y = 1;
182 } else {
183 rect.p0.x = params.rect.p1.x - 80;
184 rect.p0.y = 4;
185 rect.p1.x = params.rect.p1.x - 4;
186 rect.p1.y = 32 - 4;
187 }
188
[50a16d9]189 taskbar_clock_set_rect(taskbar->clock, &rect);
190
191 rc = ui_fixed_add(taskbar->fixed, taskbar_clock_ctl(taskbar->clock));
192 if (rc != EOK) {
193 printf("Error adding control to layout.\n");
194 taskbar_clock_destroy(taskbar->clock);
195 goto error;
196 }
197
[2139676]198 ui_window_add(taskbar->window, ui_fixed_ctl(taskbar->fixed));
199
200 rc = ui_window_paint(taskbar->window);
201 if (rc != EOK) {
202 printf("Error painting window.\n");
203 goto error;
204 }
205
206 *rtaskbar = taskbar;
207 return EOK;
208error:
[50a16d9]209 if (taskbar->clock != NULL)
210 taskbar_clock_destroy(taskbar->clock);
[e0e612b]211 if (taskbar->wndlist != NULL)
212 wndlist_destroy(taskbar->wndlist);
[2139676]213 if (taskbar->window != NULL)
214 ui_window_destroy(taskbar->window);
215 if (taskbar->ui != NULL)
216 ui_destroy(taskbar->ui);
217 return rc;
218
219}
220
221/** Destroy task bar. */
222void taskbar_destroy(taskbar_t *taskbar)
223{
[c77cfd8]224 ui_fixed_remove(taskbar->fixed, taskbar_clock_ctl(taskbar->clock));
[50a16d9]225 taskbar_clock_destroy(taskbar->clock);
[2139676]226 ui_window_destroy(taskbar->window);
227 ui_destroy(taskbar->ui);
228}
229
230/** @}
231 */
Note: See TracBrowser for help on using the repository browser.