source: mainline/uspace/app/taskbar/wndlist.c@ 7a05d924

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

Return correct number of windows from display server

But not the caption since the display server does not have it

  • Property mode set to 100644
File size: 4.5 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 window list
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 "clock.h"
45#include "wndlist.h"
46
47/** Create task bar window list.
48 *
49 * @param res UI resource
50 * @param fixed Fixed layout to which buttons will be added
51 * @param wndmgt Window management service
52 * @param rwndlist Place to store pointer to new window list
53 * @return @c EOK on success or an error code
54 */
55errno_t wndlist_create(ui_resource_t *res, ui_fixed_t *fixed,
56 wndlist_t **rwndlist)
57{
58 wndlist_t *wndlist = NULL;
59 errno_t rc;
60
61 wndlist = calloc(1, sizeof(wndlist_t));
62 if (wndlist == NULL) {
63 rc = ENOMEM;
64 goto error;
65 }
66
67 wndlist->res = res;
68 wndlist->fixed = fixed;
69 list_initialize(&wndlist->entries);
70 *rwndlist = wndlist;
71 return EOK;
72error:
73 return rc;
74}
75
76/** Attach window management service to window list.
77 *
78 * @param wndlist Window list
79 * @param rwndlist Place to store pointer to new window list
80 * @return @c EOK on success or an error code
81 */
82errno_t wndlist_attach_wm(wndlist_t *wndlist, wndmgt_t *wndmgt)
83{
84 errno_t rc;
85 wndmgt_window_list_t *wlist = NULL;
86 wndmgt_window_info_t *winfo = NULL;
87 sysarg_t i;
88
89 rc = wndmgt_get_window_list(wndmgt, &wlist);
90 if (rc != EOK)
91 goto error;
92
93 for (i = 0; i < wlist->nwindows; i++) {
94 rc = wndmgt_get_window_info(wndmgt, wlist->windows[i],
95 &winfo);
96 if (rc != EOK)
97 goto error;
98
99 rc = wndlist_append(wndlist, winfo->caption);
100 if (rc != EOK) {
101 wndmgt_free_window_info(winfo);
102 goto error;
103 }
104
105 wndmgt_free_window_info(winfo);
106 }
107
108 wndlist->wndmgt = wndmgt;
109 return EOK;
110error:
111 if (wlist != NULL)
112 wndmgt_free_window_list(wlist);
113 return rc;
114}
115
116/** Destroy task bar window list. */
117void wndlist_destroy(wndlist_t *wndlist)
118{
119 free(wndlist);
120}
121
122/** Append new entry to window list.
123 *
124 * @param wndlist Window list
125 * @param caption Entry caption
126 * @return @c EOK on success or an error code
127 */
128errno_t wndlist_append(wndlist_t *wndlist, const char *caption)
129{
130 wndlist_entry_t *entry = NULL;
131 gfx_rect_t rect;
132 size_t nentries;
133 errno_t rc;
134
135 /* Number of existing entries */
136 nentries = list_count(&wndlist->entries);
137
138 entry = calloc(1, sizeof(wndlist_entry_t));
139 if (entry == NULL) {
140 rc = ENOMEM;
141 goto error;
142 }
143
144 rc = ui_pbutton_create(wndlist->res, caption, &entry->button);
145 if (rc != EOK)
146 goto error;
147
148 if (ui_resource_is_textmode(wndlist->res)) {
149 rect.p0.x = 17 * nentries + 9;
150 rect.p0.y = 0;
151 rect.p1.x = 17 * nentries + 25;
152 rect.p1.y = 1;
153 } else {
154 rect.p0.x = 145 * nentries + 90;
155 rect.p0.y = 3;
156 rect.p1.x = 145 * nentries + 230;
157 rect.p1.y = 29;
158 }
159
160 ui_pbutton_set_rect(entry->button, &rect);
161
162 rc = ui_fixed_add(wndlist->fixed, ui_pbutton_ctl(entry->button));
163 if (rc != EOK)
164 goto error;
165
166 entry->wndlist = wndlist;
167 list_append(&entry->lentries, &wndlist->entries);
168
169 return EOK;
170error:
171 if (entry != NULL && entry->button != NULL)
172 ui_pbutton_destroy(entry->button);
173 if (entry != NULL)
174 free(entry);
175 return rc;
176
177}
178
179/** @}
180 */
Note: See TracBrowser for help on using the repository browser.