File: socket.c

package info (click to toggle)
luakit 2012.09.13-r1-8
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 1,160 kB
  • ctags: 1,276
  • sloc: ansic: 6,086; makefile: 153; ruby: 79; sh: 38
file content (91 lines) | stat: -rw-r--r-- 2,476 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
 * widgets/socket.c - gtk socket widget
 *
 * Copyright © 2010-2011 Fabian Streitel <karottenreibe@gmail.com>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#include "luah.h"
#include "widgets/common.h"
#include <stdlib.h>

static void
plug_added_cb(GtkSocket* UNUSED(socket), widget_t *w)
{
    lua_State *L = globalconf.L;
    luaH_object_push(L, w->ref);
    luaH_object_emit_signal(L, -1, "plug-added", 1, 0);
}

static gboolean
plug_removed_cb(GtkSocket* UNUSED(socket), widget_t *w)
{
    lua_State *L = globalconf.L;
    luaH_object_push(L, w->ref);
    luaH_object_emit_signal(L, -1, "plug-removed", 1, 0);
    return FALSE;
}

static gint
luaH_socket_index(lua_State *L, widget_t *w, luakit_token_t token)
{
    switch(token) {
      LUAKIT_WIDGET_INDEX_COMMON(w)

      /* push integer methods */
      PI_CASE(ID,      (int) gtk_socket_get_id(GTK_SOCKET(w->widget)))
      /* push boolean methods */
      PB_CASE(PLUGGED, gtk_socket_get_plug_window(GTK_SOCKET(w->widget))!=NULL)

      default:
        break;
    }
    return 0;
}

static gint
luaH_socket_newindex(lua_State *L, widget_t *w, luakit_token_t token)
{
    switch(token) {
      LUAKIT_WIDGET_INDEX_COMMON(w)

      case L_TK_ID:
        gtk_socket_add_id(GTK_SOCKET(w->widget),
                (GdkNativeWindow) luaL_checkint(L, 2));
        break;

      default:
        break;
    }
    return 0;
}

widget_t *
widget_socket(widget_t *w, luakit_token_t UNUSED(token))
{
    w->index = luaH_socket_index;
    w->newindex = luaH_socket_newindex;
    w->destructor = widget_destructor;

    w->widget = gtk_socket_new();
    gtk_widget_show(w->widget);
    g_object_connect(G_OBJECT(w->widget),
      LUAKIT_WIDGET_SIGNAL_COMMON(w)
      "signal::plug-added",   G_CALLBACK(plug_added_cb),   w,
      "signal::plug-removed", G_CALLBACK(plug_removed_cb), w,
      NULL);
    return w;
}