libxputty 0.1
Loading...
Searching...
No Matches
xchildlist.c
Go to the documentation of this file.
1/*
2 * 0BSD
3 *
4 * BSD Zero Clause License
5 *
6 * Copyright (c) 2019 Hermann Meyer
7 *
8 * Permission to use, copy, modify, and/or distribute this software for any
9 * purpose with or without fee is hereby granted.
10
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
12 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13 * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
14 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
16 * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17 * PERFORMANCE OF THIS SOFTWARE.
18 *
19 */
20
21#include "xchildlist.h"
22#include "xchildlist_private.h"
23
24
25void childlist_init(Childlist_t *childlist) {
26 childlist->childs = (Widget_t**)malloc(sizeof(Widget_t*) * 4);
27 assert(childlist->childs != NULL);
28 memset(childlist->childs, 0, 4 * sizeof(Widget_t*));
29 childlist->cap =4;
30 childlist->size = sizeof(childlist);
31 childlist->elem = 0;
32 int i = 0;
33 for(;i<childlist->cap;i++) {
34 childlist->childs[i] = NULL;
35 }
36}
37
39 if(childlist) free(childlist->childs);
40}
41
42void childlist_add_child(Childlist_t *childlist, Widget_t *child) {
43 if(!childlist) childlist_init(childlist);
44 if (childlist->cap < childlist->elem+2) {
45 _childlist_add_elem(childlist);
46 }
47 childlist->childs[childlist->elem] = child;
48 debug_print("Childlist_t add_child\n");
49 if (child->flags & IS_WINDOW) {
51 }
52 childlist->elem +=1;
53}
54
56 if (!childlist) return;
57 int it = childlist_find_child(childlist, child);
58 if(it >= 0){
59 childlist->childs[it] = NULL;
60 childlist->elem--;
61 int i = it;
62 for(;i<childlist->elem;i++) {
63 childlist->childs[i] = childlist->childs[i+1];
64 }
65 childlist->childs[childlist->elem+1] = NULL;
66 }
67}
68
69int childlist_find_child(Childlist_t *childlist, Widget_t *child) {
70 int i = 0;
71 for(;i<childlist->elem;i++) {
72 if(childlist->childs[i] == child) {
73 return i;
74 }
75 }
76 return -1;
77}
78
79int childlist_find_widget(Childlist_t *childlist, Window child_window) {
80 int i = childlist->elem-1;
81 for(;i>-1;i--) {
82 if(childlist->childs[i]->widget == child_window) {
83 return i;
84 }
85 }
86 return -1;
87}
88
90 return childlist->elem;
91}
Childlist_t - struct to hold a Widget_t child list Xputty main holds a list of any Widget_t created...
Definition xchildlist.h:49
Widget_t ** childs
Definition xchildlist.h:51
size_t size
Definition xchildlist.h:53
Widget_t - struct to hold the basic Widget_t info.
Definition xwidget.h:457
Window widget
Definition xwidget.h:469
long long flags
Definition xwidget.h:461
void childlist_add_child(Childlist_t *childlist, Widget_t *child)
childlist_add_child - internal use to add a child to the Childlist_t You usually didn't need to cal...
Definition xchildlist.c:42
int childlist_find_child(Childlist_t *childlist, Widget_t *child)
childlist_find_child - find a child in a the Childlist_t this could be sued to check if a Widget_t is...
Definition xchildlist.c:69
void childlist_destroy(Childlist_t *childlist)
childlist_destroy - internal use to free the Childlist_t You usually didn't need to call this
Definition xchildlist.c:38
void childlist_remove_child(Childlist_t *childlist, Widget_t *child)
childlist_remove_child - internal use to remove a child from the childlist You usually didn't need ...
Definition xchildlist.c:55
int childlist_find_widget(Childlist_t *childlist, Window child_window)
childlist_find_widget - find a child Widget_t in a the childlist by given the Window id
Definition xchildlist.c:79
void childlist_init(Childlist_t *childlist)
childlist_init - internal use to allocate the array to min size You usually didn't need to call thi...
Definition xchildlist.c:25
int childlist_has_child(Childlist_t *childlist)
childlist_has_child - check if a Widget_t Childlist_t contain a child
Definition xchildlist.c:89
void _childlist_add_elem(Childlist_t *childlist)
_childlist_add_elem - internal use to reallocate the childlist array to new size You didn't need to...
HWND Window
Atom os_register_wm_delete_window(Widget_t *wid)
os_register_wm_delete_window - Get the needed Atom to send a widget delete message
@ IS_WINDOW
Definition xwidget.h:390