button.c - ltk - GUI toolkit for X11 (WIP)
HTML git clone git://lumidify.org/ltk.git (fast, but not encrypted)
HTML git clone https://lumidify.org/ltk.git (encrypted, but very slow)
HTML git clone git://4kcetb7mo7hj6grozzybxtotsub5bempzo4lirzc3437amof2c2impyd.onion/ltk.git (over tor)
DIR Log
DIR Files
DIR Refs
DIR README
DIR LICENSE
---
button.c (2296B)
---
1 /*
2 * Copyright (c) 2016-2024 lumidify <nobody@lumidify.org>
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17 #include <stddef.h>
18
19 #include "err.h"
20 #include "ltkd.h"
21 #include "widget.h"
22 #include "cmd.h"
23 #include "proto_types.h"
24
25 #include <ltk/ltk.h>
26 #include <ltk/util.h>
27 #include <ltk/button.h>
28
29 static int
30 ltkd_button_press(ltk_widget *widget_unused, ltk_callback_arglist args, ltk_callback_arg arg) {
31 (void)widget_unused;
32 (void)args;
33 ltkd_widget *widget = LTK_CAST_ARG_VOIDP(arg);
34 return ltkd_widget_queue_specific_event(widget, "button", LTKD_PWEVENTMASK_BUTTON_PRESS, "press");
35 }
36
37 static ltkd_event_handler handlers[] = {
38 {<kd_button_press, LTK_BUTTON_SIGNAL_PRESSED},
39 };
40
41 /* button <button id> create <text> */
42 static int
43 ltkd_button_cmd_create(
44 ltk_window *window,
45 ltkd_widget *widget_unneeded,
46 ltkd_cmd_token *tokens,
47 size_t num_tokens,
48 ltkd_error *err) {
49 (void)widget_unneeded;
50 ltkd_cmdarg_parseinfo cmd[] = {
51 {.type = CMDARG_IGNORE, .optional = 0},
52 {.type = CMDARG_STRING, .optional = 0},
53 {.type = CMDARG_IGNORE, .optional = 0},
54 {.type = CMDARG_STRING, .optional = 0},
55 };
56 if (ltkd_parse_cmd(tokens, num_tokens, cmd, LENGTH(cmd), err))
57 return 1;
58 ltk_button *button = ltk_button_create(window, cmd[3].val.str);
59 if (!ltkd_widget_create(LTK_CAST_WIDGET(button), cmd[1].val.str, handlers, LENGTH(handlers), err)) {
60 ltk_widget_destroy(LTK_CAST_WIDGET(button), 1);
61 err->arg = 1;
62 return 1;
63 }
64
65 return 0;
66 }
67
68 static ltkd_cmd_info button_cmds[] = {
69 {"create", <kd_button_cmd_create, 1},
70 };
71
72 GEN_CMD_HELPERS(ltkd_button_cmd, LTK_WIDGET_BUTTON, button_cmds)