rofi 1.7.8
container.c
Go to the documentation of this file.
1/*
2 * rofi
3 *
4 * MIT/X11 License
5 * Copyright © 2013-2023 Qball Cow <qball@gmpclient.org>
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining
8 * a copy of this software and associated documentation files (the
9 * "Software"), to deal in the Software without restriction, including
10 * without limitation the rights to use, copy, modify, merge, publish,
11 * distribute, sublicense, and/or sell copies of the Software, and to
12 * permit persons to whom the Software is furnished to do so, subject to
13 * the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be
16 * included in all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
22 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 */
27
29#define G_LOG_DOMAIN "Widgets.Container"
30#include "config.h"
31
32#include "theme.h"
33#include "widgets/container.h"
35#include "widgets/widget.h"
36#include <stdio.h>
37
42
43static void container_update(widget *wid);
44
45static int container_get_desired_height(widget *wid, const int width) {
46 container *b = (container *)wid;
47 int height = 0;
48 if (b->child) {
49 height += widget_get_desired_height(b->child, width);
50 }
52 return height;
53}
54
55static void container_draw(widget *wid, cairo_t *draw) {
56 container *b = (container *)wid;
57
58 widget_draw(b->child, draw);
59}
60
61static void container_free(widget *wid) {
62 container *b = (container *)wid;
63
65 g_free(b);
66}
67
68void container_add(container *cont, widget *child) {
69 if (cont == NULL) {
70 return;
71 }
72 cont->child = child;
73 g_assert(child->parent == WIDGET(cont));
74 widget_update(WIDGET(cont));
75}
76
77static void container_resize(widget *wid, short w, short h) {
78 container *b = (container *)wid;
79 if (b->widget.w != w || b->widget.h != h) {
80 b->widget.w = w;
81 b->widget.h = h;
82 widget_update(wid);
83 }
84}
85
87 gint y) {
88 container *b = (container *)wid;
89 if (!widget_intersect(b->child, x, y)) {
90 return NULL;
91 }
92
93 x -= b->child->x;
94 y -= b->child->y;
95 return widget_find_mouse_target(b->child, type, x, y);
96}
97
98static void container_set_state(widget *wid, const char *state) {
99 container *b = (container *)wid;
100 widget_set_state(b->child, state);
101}
102
103container *container_create(widget *parent, const char *name) {
104 container *b = g_malloc0(sizeof(container));
105 // Initialize widget.
106 widget_init(WIDGET(b), parent, WIDGET_TYPE_UNKNOWN, name);
114 return b;
115}
116
static int container_get_desired_height(widget *wid, const int width)
Definition container.c:45
static void container_resize(widget *wid, short w, short h)
Definition container.c:77
static void container_set_state(widget *wid, const char *state)
Definition container.c:98
static void container_draw(widget *wid, cairo_t *draw)
Definition container.c:55
static widget * container_find_mouse_target(widget *wid, WidgetType type, gint x, gint y)
Definition container.c:86
static void container_free(widget *wid)
Definition container.c:61
static void container_update(widget *wid)
Definition container.c:117
void container_add(container *cont, widget *child)
Definition container.c:68
struct _container container
Definition container.h:44
container * container_create(widget *parent, const char *name)
Definition container.c:103
void widget_move(widget *wid, short x, short y)
Definition widget.c:102
void widget_free(widget *wid)
Definition widget.c:415
void widget_draw(widget *wid, cairo_t *d)
Definition widget.c:135
struct _widget widget
Definition widget.h:51
void widget_update(widget *wid)
Definition widget.c:467
WidgetType
Definition widget.h:56
void widget_resize(widget *wid, short w, short h)
Definition widget.c:87
#define WIDGET(a)
Definition widget.h:119
int widget_get_desired_height(widget *wid, const int width)
Definition widget.c:634
int widget_intersect(const widget *wid, int x, int y)
Definition widget.c:75
widget * widget_find_mouse_target(widget *wid, WidgetType type, gint x, gint y)
Definition widget.c:500
@ WIDGET_TYPE_UNKNOWN
Definition widget.h:58
widget * child
Definition container.c:40
widget widget
Definition container.c:39
void(* free)(struct _widget *widget)
void(* set_state)(struct _widget *, const char *)
widget_find_mouse_target_cb find_mouse_target
gboolean enabled
int(* get_desired_height)(struct _widget *, const int width)
struct _widget * parent
void(* update)(struct _widget *)
void(* draw)(struct _widget *widget, cairo_t *draw)
void(* resize)(struct _widget *, short, short)
int widget_padding_get_remaining_width(const widget *wid)
Definition widget.c:609
void widget_set_state(widget *wid, const char *state)
Definition widget.c:58
void widget_init(widget *wid, widget *parent, WidgetType type, const char *name)
Definition widget.c:35
int widget_padding_get_left(const widget *wid)
Definition widget.c:566
int widget_padding_get_padding_height(const widget *wid)
Definition widget.c:621
int widget_padding_get_top(const widget *wid)
Definition widget.c:588
int widget_padding_get_remaining_height(const widget *wid)
Definition widget.c:615