예제 #1
0
파일: scroll.c 프로젝트: glindste/luakit
static gint
luaH_webview_scroll_index(lua_State *L)
{
    webview_data_t *d = luaH_checkwvdata(L, lua_upvalueindex(1));
    const gchar *prop = luaL_checkstring(L, 2);
    luakit_token_t t = l_tokenize(prop);

    GtkAdjustment *a = (*prop == 'x') ?
                       gtk_scrolled_window_get_hadjustment(d->win)
                       : gtk_scrolled_window_get_vadjustment(d->win);

    if (t == L_TK_X || t == L_TK_Y) {
        lua_pushnumber(L, gtk_adjustment_get_value(a));
        return 1;

    } else if (t == L_TK_XMAX || t == L_TK_YMAX) {
        lua_pushnumber(L, gtk_adjustment_get_upper(a) -
                       gtk_adjustment_get_page_size(a));
        return 1;

    } else if (t == L_TK_XPAGE_SIZE || t == L_TK_YPAGE_SIZE) {
        lua_pushnumber(L, gtk_adjustment_get_page_size(a));
        return 1;
    }
    return 0;
}
예제 #2
0
파일: luah.c 프로젝트: pawelz/luakit
/* luakit global table.
 * \param L The Lua VM state.
 * \return The number of elements pushed on stack.
 * \luastack
 * \lfield font The default font.
 * \lfield font_height The default font height.
 * \lfield conffile The configuration file which has been loaded.
 */
static gint
luaH_luakit_index(lua_State *L)
{
    if(luaH_usemetatable(L, 1, 2))
        return 1;

    widget_t *w;
    const gchar *prop = luaL_checkstring(L, 2);
    luakit_token_t token = l_tokenize(prop);

    switch(token) {

      /* push class methods */
      PF_CASE(GET_SPECIAL_DIR,  luaH_luakit_get_special_dir)
      PF_CASE(SPAWN,            luaH_luakit_spawn)
      PF_CASE(SPAWN_SYNC,       luaH_luakit_spawn_sync)
      PF_CASE(GET_SELECTION,    luaH_luakit_get_selection)
      PF_CASE(SET_SELECTION,    luaH_luakit_set_selection)
      PF_CASE(EXEC,             luaH_exec)
      /* push string properties */
      PS_CASE(CACHE_DIR,        globalconf.cache_dir)
      PS_CASE(CONFIG_DIR,       globalconf.config_dir)
      PS_CASE(DATA_DIR,         globalconf.data_dir)
      PS_CASE(EXECPATH,         globalconf.execpath)
      PS_CASE(CONFPATH,         globalconf.confpath)
      /* push boolean properties */
      PB_CASE(VERBOSE,          globalconf.verbose)
      /* push integer properties */
      PI_CASE(WEBKIT_MAJOR_VERSION, webkit_major_version())
      PI_CASE(WEBKIT_MINOR_VERSION, webkit_minor_version())
      PI_CASE(WEBKIT_MICRO_VERSION, webkit_micro_version())
      PI_CASE(WEBKIT_USER_AGENT_MAJOR_VERSION, WEBKIT_USER_AGENT_MAJOR_VERSION)
      PI_CASE(WEBKIT_USER_AGENT_MINOR_VERSION, WEBKIT_USER_AGENT_MINOR_VERSION)

      case L_TK_WINDOWS:
        lua_newtable(L);
        for (guint i = 0; i < globalconf.windows->len; i++) {
            w = globalconf.windows->pdata[i];
            luaH_object_push(L, w->ref);
            lua_rawseti(L, -2, i+1);
        }
        return 1;

      case L_TK_INSTALL_PATH:
        lua_pushliteral(L, LUAKIT_INSTALL_PATH);
        return 1;

      case L_TK_VERSION:
        lua_pushliteral(L, VERSION);
        return 1;

      default:
        break;
    }
    return 0;
}
예제 #3
0
파일: scroll.c 프로젝트: glindste/luakit
static gint
luaH_webview_scroll_newindex(lua_State *L)
{
    /* get webview widget upvalue */
    webview_data_t *d = luaH_checkwvdata(L, lua_upvalueindex(1));
    const gchar *prop = luaL_checkstring(L, 2);
    luakit_token_t t = l_tokenize(prop);

    GtkAdjustment *a;
    if (t == L_TK_X)      a = gtk_scrolled_window_get_hadjustment(d->win);
    else if (t == L_TK_Y) a = gtk_scrolled_window_get_vadjustment(d->win);
    else return 0;

    gdouble value = luaL_checknumber(L, 3);
    gdouble max = gtk_adjustment_get_upper(a) -
                  gtk_adjustment_get_page_size(a);
    gtk_adjustment_set_value(a, ((value < 0 ? 0 : value) > max ? max : value));
    return 0;
}
예제 #4
0
파일: box.c 프로젝트: aidanholm/luakit
static gint
luaH_box_pack(lua_State *L)
{
    widget_t *w = luaH_checkwidget(L, 1);
    widget_t *child = luaH_checkwidget(L, 2);

    gint top = lua_gettop(L);
    gboolean expand = FALSE, fill = FALSE, start = TRUE;
    guint padding = 0;

    /* check for options table */
    if (top > 2 && !lua_isnil(L, 3)) {
        luaH_checktable(L, 3);

        /* pack child from start or end of container? */
        if (luaH_rawfield(L, 3, "from"))
            start = L_TK_END == l_tokenize(lua_tostring(L, -1)) ? FALSE : TRUE;

        /* expand? */
        if (luaH_rawfield(L, 3, "expand"))
            expand = lua_toboolean(L, -1) ? TRUE : FALSE;

        /* fill? */
        if (luaH_rawfield(L, 3, "fill"))
            fill = lua_toboolean(L, -1) ? TRUE : FALSE;

        /* padding? */
        if (luaH_rawfield(L, 3, "padding"))
            padding = (guint)lua_tonumber(L, -1);

        /* return stack to original state */
        lua_settop(L, top);
    }

    if (start)
        gtk_box_pack_start(GTK_BOX(w->widget), GTK_WIDGET(child->widget),
                expand, fill, padding);
    else
        gtk_box_pack_end(GTK_BOX(w->widget), GTK_WIDGET(child->widget),
                expand, fill, padding);
    return 0;
}
예제 #5
0
파일: luah.c 프로젝트: pawelz/luakit
static gint
luaH_luakit_get_special_dir(lua_State *L)
{
    const gchar *name = luaL_checkstring(L, 1);
    luakit_token_t token = l_tokenize(name);
    GUserDirectory atom;
    /* match token with G_USER_DIR_* atom */
    switch(token) {
      case L_TK_DESKTOP:      atom = G_USER_DIRECTORY_DESKTOP;      break;
      case L_TK_DOCUMENTS:    atom = G_USER_DIRECTORY_DOCUMENTS;    break;
      case L_TK_DOWNLOAD:     atom = G_USER_DIRECTORY_DOWNLOAD;     break;
      case L_TK_MUSIC:        atom = G_USER_DIRECTORY_MUSIC;        break;
      case L_TK_PICTURES:     atom = G_USER_DIRECTORY_PICTURES;     break;
      case L_TK_PUBLIC_SHARE: atom = G_USER_DIRECTORY_PUBLIC_SHARE; break;
      case L_TK_TEMPLATES:    atom = G_USER_DIRECTORY_TEMPLATES;    break;
      case L_TK_VIDEOS:       atom = G_USER_DIRECTORY_VIDEOS;       break;
      default:
        warn("unknown atom G_USER_DIRECTORY_%s", name);
        luaL_argerror(L, 1, "invalid G_USER_DIRECTORY_* atom");
        return 0;
    }
    lua_pushstring(L, g_get_user_special_dir(atom));
    return 1;
}