libxputty  0.1
A damn tiny abstraction Layer to create X11 window/widgets with cairo surfaces
xchildlist.h File Reference
#include "xputty.h"
Include dependency graph for xchildlist.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  Childlist_t
 Childlist_t - struct to hold a Widget_t child list
Xputty main holds a list of any Widget_t created in relation to main
Any Event is only propagate to Widget_t's found in this list
Every Widget_t holds a list of Child Widget_t's they contain
When a Widget_t get destroy_widget() call, all of it's childs receive a destroy_widget() call before the Widget_t itself get destroyed
the expose_callback() (EXPOSE) and the configure_callback() (CONFIGURE) will be propagate to all childs in a Childlist_t. More...
 

Macros

#define XCHILDLIST_H_
 

Functions

void childlist_init (Childlist_t *childlist)
 childlist_init - internal use to allocate the array to min size
You usually didn't need to call this More...
 
void childlist_destroy (Childlist_t *childlist)
 childlist_destroy - internal use to free the Childlist_t
You usually didn't need to call this More...
 
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 call this More...
 
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 to call this More...
 
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 a child of a other Widget_t More...
 
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 More...
 
int childlist_has_child (Childlist_t *childlist)
 childlist_has_child - check if a Widget_t Childlist_t contain a child More...
 

Macro Definition Documentation

◆ XCHILDLIST_H_

#define XCHILDLIST_H_

Definition at line 24 of file xchildlist.h.

Function Documentation

◆ childlist_add_child()

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 call this

Parameters
*childlist- pointer to the Childlist_t
*child- pointer to the child to add
Returns
void

Definition at line 42 of file xchildlist.c.

42  {
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) {
50  Atom WM_DELETE_WINDOW;
51  WM_DELETE_WINDOW = XInternAtom(child->app->dpy, "WM_DELETE_WINDOW", True);
52  XSetWMProtocols(child->app->dpy, child->widget, &WM_DELETE_WINDOW, 1);
53  }
54  childlist->elem +=1;
55 }

References _childlist_add_elem(), Widget_t::app, Childlist_t::cap, childlist_init(), Childlist_t::childs, debug_print, Xputty::dpy, Childlist_t::elem, Widget_t::flags, IS_WINDOW, and Widget_t::widget.

◆ childlist_destroy()

void childlist_destroy ( Childlist_t childlist)

childlist_destroy - internal use to free the Childlist_t
You usually didn't need to call this

Parameters
*childlist- pointer to the Childlist_t
Returns
void

Definition at line 38 of file xchildlist.c.

38  {
39  if(childlist) free(childlist->childs);
40 }

References Childlist_t::childs.

◆ childlist_find_child()

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 a child of a other Widget_t

Parameters
*childlist- pointer to the Childlist_t
*child- pointer to the child to find
Returns
int - return position in childlist or -1 when not found

Definition at line 71 of file xchildlist.c.

71  {
72  int i = 0;
73  for(;i<childlist->elem;i++) {
74  if(childlist->childs[i] == child) {
75  return i;
76  }
77  }
78  return -1;
79 }

References Childlist_t::childs, and Childlist_t::elem.

◆ childlist_find_widget()

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

Parameters
*childlist- pointer to the Childlist_t
child_window- the Window to find the Widget_t for
Returns
int - return position in childlist or -1 when not found

Definition at line 81 of file xchildlist.c.

81  {
82  int i = childlist->elem-1;
83  for(;i>-1;i--) {
84  if(childlist->childs[i]->widget == child_window) {
85  return i;
86  }
87  }
88  return -1;
89 }

References Childlist_t::childs, Childlist_t::elem, and Widget_t::widget.

◆ childlist_has_child()

int childlist_has_child ( Childlist_t childlist)

childlist_has_child - check if a Widget_t Childlist_t contain a child

Parameters
*childlist- pointer to the Childlist_t
Returns
int - return element counter value 0 when Widget_t Childlist_t didn't contain a child

Definition at line 91 of file xchildlist.c.

91  {
92  return childlist->elem;
93 }

References Childlist_t::elem.

◆ childlist_init()

void childlist_init ( Childlist_t childlist)

childlist_init - internal use to allocate the array to min size
You usually didn't need to call this

Parameters
*childlist- pointer to the Childlist_t
Returns
void

Definition at line 25 of file xchildlist.c.

25  {
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 }

References Childlist_t::cap, Childlist_t::childs, Childlist_t::elem, and Childlist_t::size.

◆ childlist_remove_child()

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 to call this

Parameters
*childlist- pointer to the Childlist_t
*child- pointer to the child to remove
Returns
void

Definition at line 57 of file xchildlist.c.

57  {
58  if (!childlist) return;
59  int it = childlist_find_child(childlist, child);
60  if(it >= 0){
61  childlist->childs[it] = NULL;
62  childlist->elem--;
63  int i = it;
64  for(;i<childlist->elem;i++) {
65  childlist->childs[i] = childlist->childs[i+1];
66  }
67  childlist->childs[childlist->elem+1] = NULL;
68  }
69 }

References childlist_find_child(), Childlist_t::childs, and Childlist_t::elem.

_childlist_add_elem
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...
Definition: xchildlist_private.c:23
Childlist_t::childs
Widget_t ** childs
Definition: xchildlist.h:51
IS_WINDOW
@ IS_WINDOW
Definition: xwidget.h:235
Widget_t::flags
long long flags
Definition: xwidget.h:324
childlist_init
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
Childlist_t::cap
int cap
Definition: xchildlist.h:55
Widget_t::app
Xputty * app
Definition: xwidget.h:300
Xputty::dpy
Display * dpy
Definition: xputty.h:181
Widget_t::widget
Window widget
Definition: xwidget.h:302
debug_print
#define debug_print(...)
debug_print - print out state messages when compiled with the -DDEBUG flag
Definition: xputty.h:64
Widget_t
Widget_t - struct to hold the basic Widget_t info.
Definition: xwidget.h:298
Childlist_t::size
size_t size
Definition: xchildlist.h:53
Childlist_t::elem
int elem
Definition: xchildlist.h:57
childlist_find_child
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:71