1 /* Copyright (c) 2008 Vincent Povirk
3 Permission is hereby granted, free of charge, to any person
4 obtaining a copy of this software and associated documentation
5 files (the "Software"), to deal in the Software without
6 restriction, including without limitation the rights to use,
7 copy, modify, merge, publish, distribute, sublicense, and/or sell
8 copies of the Software, and to permit persons to whom the
9 Software is furnished to do so, subject to the following
12 The above copyright notice and this permission notice shall be
13 included in all copies or substantial portions of the Software.
15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17 OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 OTHER DEALINGS IN THE SOFTWARE.
28 #include <readline/readline.h>
32 #include "lucca-layout.h"
34 GList
* refs
=NULL
; /* a list of objects that we hold a reference to; this lets us unref and hopefully free everything when the tests end */
36 void on_deletetile(LuccaLayoutTile
* tile
, gpointer user_data
) {
37 g_print("delete %p\n", tile
);
40 void on_configuretile(LuccaLayoutTile
* tile
, gpointer user_data
) {
41 g_print("configure %p\n", tile
);
44 void on_newtile(LuccaLayout
* layout
, LuccaLayoutTile
* tile
, gpointer user_data
) {
45 g_print("new-tile %p\n", tile
);
47 g_signal_connect(tile
, "delete", G_CALLBACK(on_deletetile
), NULL
);
48 g_signal_connect(tile
, "configure", G_CALLBACK(on_configuretile
), NULL
);
50 g_object_ref(tile
); /* store a reference to every tile so they're never destroyed */
51 refs
= g_list_prepend(refs
, tile
);
55 LuccaLayout
* layout
=NULL
;
57 GdkWindowHints hints_mask
;
58 char* input_line
=NULL
;
59 gchar
** input_words
=NULL
;
66 g_type_init(); /* initialize the type system */
68 layout
= g_object_new(LUCCA_TYPE_LAYOUT
, NULL
);
70 g_signal_connect(layout
, "new-tile", G_CALLBACK(on_newtile
), NULL
);
72 g_print("layout %p\n", layout
);
75 input_line
= readline("");
76 if (input_line
== NULL
) {
79 input_words
= g_strsplit(input_line
, " ", 0);
80 if ((input_words
[0] == NULL
) || (g_ascii_strcasecmp(input_words
[0], "quit") == 0)) {
82 g_strfreev(input_words
);
85 else if (g_ascii_strcasecmp(input_words
[0], "init") == 0) {
86 lucca_layout_initialize(layout
, strtol(input_words
[1], NULL
, 10), strtol(input_words
[2], NULL
, 10), strtol(input_words
[3], NULL
, 10), hints
, hints_mask
);
88 else if (g_ascii_strcasecmp(input_words
[0], "getui") == 0) {
89 obj
= G_OBJECT(strtol(input_words
[1]+2, NULL
, 16));
90 g_object_get(obj
, input_words
[2], &uivalue
, NULL
);
91 g_print("%i\n", uivalue
);
93 else if (g_ascii_strcasecmp(input_words
[0], "getb") == 0) {
94 obj
= G_OBJECT(strtol(input_words
[1]+2, NULL
, 16));
95 g_object_get(obj
, input_words
[2], &bvalue
, NULL
);
96 g_print("%i\n", bvalue
);
98 else if (g_ascii_strcasecmp(input_words
[0], "deinit") == 0) {
99 lucca_layout_deinit(layout
);
101 else if (g_ascii_strcasecmp(input_words
[0], "get_tile_at_position") == 0) {
102 g_print("%p\n", lucca_layout_get_tile_at_position(layout
, strtol(input_words
[1], NULL
, 10), strtol(input_words
[2], NULL
, 10)));
104 else if (g_ascii_strcasecmp(input_words
[0], "get_tiles_in_rectangle") == 0) {
105 list
= lucca_layout_get_tiles_in_rectangle(layout
, strtol(input_words
[1], NULL
, 10), strtol(input_words
[2], NULL
, 10), strtol(input_words
[3], NULL
, 10), strtol(input_words
[4], NULL
, 10));
106 for (listi
=list
; listi
!= NULL
; listi
=listi
->next
) {
107 g_print("%p ", listi
->data
);
112 else if (g_ascii_strcasecmp(input_words
[0], "get_tiles") == 0) {
113 list
= lucca_layout_get_tiles(layout
);
114 for (listi
=list
; listi
!= NULL
; listi
=listi
->next
) {
115 g_print("%p ", listi
->data
);
120 else if (g_ascii_strcasecmp(input_words
[0], "get_layout") == 0) {
121 g_print("%p\n", lucca_layouttile_get_layout(LUCCA_LAYOUTTILE(strtol(input_words
[1]+2, NULL
, 16))));
123 else if (g_ascii_strcasecmp(input_words
[0], "split") == 0) {
124 g_print("%p\n", lucca_layouttile_split(LUCCA_LAYOUTTILE(strtol(input_words
[1]+2, NULL
, 16)), strtol(input_words
[2], NULL
, 10), hints
, hints_mask
));
126 else if (g_ascii_strcasecmp(input_words
[0], "set_geometry_hints") == 0) {
127 lucca_layouttile_set_geometry_hints(LUCCA_LAYOUTTILE(strtol(input_words
[1]+2, NULL
, 16)), hints
, hints_mask
);
129 else if (g_ascii_strcasecmp(input_words
[0], "get_geometry_hints") == 0) {
130 lucca_layouttile_get_geometry_hints(LUCCA_LAYOUTTILE(strtol(input_words
[1]+2, NULL
, 16)), &hints
, &hints_mask
);
132 else if (g_ascii_strcasecmp(input_words
[0], "geom_set_min") == 0) {
133 hints
.min_width
= strtol(input_words
[1], NULL
, 10);
134 hints
.min_height
= strtol(input_words
[2], NULL
, 10);
135 hints_mask
|= GDK_HINT_MIN_SIZE
;
137 else if (g_ascii_strcasecmp(input_words
[0], "geom_unset_min") == 0) {
138 hints_mask
&= ~GDK_HINT_MIN_SIZE
;
140 else if (g_ascii_strcasecmp(input_words
[0], "geom_get_min") == 0) {
141 if (hints_mask
& GDK_HINT_MIN_SIZE
) {
142 g_print("%i %i\n", hints
.min_width
, hints
.min_height
);
149 g_print("no such command\n");
152 g_strfreev(input_words
);
155 g_object_unref(layout
);
157 /* free outstanding references to tiles */
158 for (listi
=refs
; listi
!= NULL
; listi
=listi
->next
) {
159 g_object_unref(G_OBJECT(listi
->data
));