2 * widgets/window.c - gtk window widget wrapper
4 * Copyright (C) 2010 Mason Larobina <mason.larobina@gmail.com>
5 * Copyright (C) 2007-2009 Julien Danjou <julien@danjou.info>
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "widgets/common.h"
26 destroy_cb(GtkObject
*win
, widget_t
*w
)
30 /* remove window from global windows list */
31 g_ptr_array_remove(globalconf
.windows
, w
);
33 lua_State
*L
= globalconf
.L
;
34 luaH_object_push(L
, w
->ref
);
35 luaH_object_emit_signal(L
, -1, "destroy", 0, 0);
40 luaH_window_index(lua_State
*L
, luakit_token_t token
)
42 widget_t
*w
= luaH_checkudata(L
, 1, &widget_class
);
46 LUAKIT_WIDGET_INDEX_COMMON
47 LUAKIT_WIDGET_BIN_INDEX_COMMON
49 /* push string methods */
50 PS_CASE(TITLE
, gtk_window_get_title(GTK_WINDOW(w
->widget
)))
59 luaH_window_newindex(lua_State
*L
, luakit_token_t token
)
62 widget_t
*w
= luaH_checkudata(L
, 1, &widget_class
);
67 gtk_window_set_title(GTK_WINDOW(w
->widget
),
68 luaL_checklstring(L
, 3, &len
));
72 gtk_window_set_icon_from_file(GTK_WINDOW(w
->widget
),
73 luaL_checklstring(L
, 3, &len
), NULL
);
80 return luaH_object_emit_property_signal(L
, 1);
84 widget_window(widget_t
*w
)
86 w
->index
= luaH_window_index
;
87 w
->newindex
= luaH_window_newindex
;
88 w
->destructor
= widget_destructor
;
90 /* create and setup window widget */
91 w
->widget
= gtk_window_new(GTK_WINDOW_TOPLEVEL
);
92 g_object_set_data(G_OBJECT(w
->widget
), "widget", (gpointer
) w
);
93 gtk_window_set_wmclass(GTK_WINDOW(w
->widget
), "luakit", "luakit");
94 gtk_window_set_default_size(GTK_WINDOW(w
->widget
), 800, 600);
95 gtk_window_set_title(GTK_WINDOW(w
->widget
), "luakit");
99 gtk_window_set_geometry_hints(GTK_WINDOW(w
->widget
), NULL
, &hints
, GDK_HINT_MIN_SIZE
);
101 g_object_connect((GObject
*)w
->widget
,
102 "signal::add", (GCallback
)add_cb
, w
,
103 "signal::destroy", (GCallback
)destroy_cb
, w
,
104 "signal::key-press-event", (GCallback
)key_press_cb
, w
,
105 "signal::remove", (GCallback
)remove_cb
, w
,
108 gtk_widget_show(w
->widget
);
109 gdk_window_set_events(GTK_WIDGET(w
->widget
)->window
, GDK_ALL_EVENTS_MASK
);
111 /* add to global windows list */
112 g_ptr_array_add(globalconf
.windows
, w
);
117 // vim: ft=c:et:sw=4:ts=8:sts=4:tw=80