├── .gitattributes ├── .gitignore ├── AUTHORS ├── CHANGELOG.md ├── CONTRIBUTING.md ├── COPYING.GPLv3 ├── Makefile ├── README.md ├── build-utils ├── docgen │ ├── gen.lua │ ├── makedoc.lua │ ├── parse.lua │ ├── process.lua │ └── style.css ├── find_files.lua ├── gentokens.lua └── getversion.sh ├── buildopts.h.in ├── clib ├── download.c ├── download.h ├── ipc.c ├── luakit.c ├── luakit.h ├── msg.c ├── msg.h ├── request.c ├── request.h ├── soup.c ├── soup.h ├── sqlite3.c ├── sqlite3.h ├── stylesheet.c ├── stylesheet.h ├── unique.c ├── unique.h ├── web_module.c ├── web_module.h ├── widget.c ├── widget.h ├── xdg.c └── xdg.h ├── common ├── clib │ ├── ipc.c │ ├── ipc.h │ ├── luakit.c │ ├── luakit.h │ ├── msg.h │ ├── regex.c │ ├── regex.h │ ├── soup.h │ ├── timer.c │ └── timer.h ├── common.h ├── ipc.c ├── ipc.h ├── log.h ├── luaclass.c ├── luaclass.h ├── luah.c ├── luah.h ├── luajs.c ├── luajs.h ├── lualib.h ├── luaobject.c ├── luaobject.h ├── luaserialize.c ├── luaserialize.h ├── luauniq.c ├── luauniq.h ├── luautil.c ├── luautil.h ├── luayield.c ├── luayield.h ├── property.c ├── property.h ├── resource.c ├── resource.h ├── signal.h ├── tokenize.list ├── util.c └── util.h ├── config.mk ├── config ├── rc.lua └── theme.lua ├── doc ├── 00-authors.md ├── docgen.ld ├── luadoc │ ├── dom_document.lua │ ├── dom_element.lua │ ├── download.lua │ ├── ipc.lua │ ├── lousy.widget.lua │ ├── luakit.lua │ ├── msg.lua │ ├── page.lua │ ├── pages │ │ ├── 01-authors.md │ │ ├── 02-faq.md │ │ ├── 03-quick-start-guide.md │ │ ├── 04-migration-guide.md │ │ ├── 05-configuration.md │ │ ├── 06-tests.md │ │ └── 07-build-debian-package.md │ ├── regex.lua │ ├── soup.lua │ ├── sqlite3.lua │ ├── stylesheet.lua │ ├── timer.lua │ ├── unique.lua │ ├── widget.box.lua │ ├── widget.drawing_area.lua │ ├── widget.entry.lua │ ├── widget.event_box.lua │ ├── widget.image.lua │ ├── widget.label.lua │ ├── widget.lua │ ├── widget.notebook.lua │ ├── widget.overlay.lua │ ├── widget.paned.lua │ ├── widget.scrolled.lua │ ├── widget.socket.lua │ ├── widget.spinner.lua │ ├── widget.webview.lua │ ├── widget.window.lua │ └── xdg.lua └── luakit.doxygen ├── extension ├── clib │ ├── dom_document.c │ ├── dom_document.h │ ├── dom_element.c │ ├── dom_element.h │ ├── ipc.c │ ├── luakit.c │ ├── luakit.h │ ├── msg.c │ ├── msg.h │ ├── page.c │ ├── page.h │ ├── soup.c │ └── soup.h ├── extension.c ├── extension.h ├── ipc.c ├── ipc.h ├── log.c ├── luajs.c ├── luajs.h ├── script_world.c ├── script_world.h ├── scroll.c └── scroll.h ├── extras ├── PKGBUILD ├── bookmarks_migrate.lua ├── convert_formfiller.rb ├── luakit.desktop ├── luakit.install ├── luakit.png └── vim │ ├── ftdetect │ └── luakit.vim │ ├── ftplugin │ └── luakit.vim │ ├── indent │ └── luakit.vim │ └── syntax │ └── luakit.vim ├── globalconf.h ├── ipc.c ├── ipc.h ├── lib ├── adblock.lua ├── adblock_chrome.lua ├── adblock_wm.lua ├── binds.lua ├── bookmarks.lua ├── bookmarks_chrome.lua ├── chrome.lua ├── chrome_wm.lua ├── cmdhist.lua ├── completion.lua ├── domain_props.lua ├── downloads.lua ├── downloads_chrome.lua ├── editor.lua ├── error_page.lua ├── error_page_wm.lua ├── follow.lua ├── follow_selected.lua ├── follow_selected_wm.lua ├── follow_wm.lua ├── formfiller.lua ├── formfiller_wm.lua ├── go_input.lua ├── go_next_prev.lua ├── go_up.lua ├── help_chrome.lua ├── hide_scrollbars.lua ├── history.lua ├── history_chrome.lua ├── image_css.lua ├── image_css_wm.lua ├── introspector_chrome.lua ├── jquery.min.js ├── log_chrome.lua ├── lousy │ ├── bind.lua │ ├── init.lua │ ├── load.lua │ ├── mode.lua │ ├── pickle.lua │ ├── signal.lua │ ├── theme.lua │ ├── uri.lua │ ├── util.lua │ └── widget │ │ ├── buf.lua │ │ ├── common.lua │ │ ├── hist.lua │ │ ├── init.lua │ │ ├── menu.lua │ │ ├── progress.lua │ │ ├── scroll.lua │ │ ├── ssl.lua │ │ ├── tab.lua │ │ ├── tabi.lua │ │ ├── tablist.lua │ │ ├── uri.lua │ │ └── zoom.lua ├── markdown.lua ├── modes.lua ├── newtab_chrome.lua ├── noscript.lua ├── open_editor.lua ├── proxy.lua ├── quickmarks.lua ├── readline.lua ├── referer_control_wm.lua ├── search.lua ├── select.lua ├── select_wm.lua ├── session.lua ├── settings.lua ├── styles.lua ├── tab_favicons.lua ├── tabhistory.lua ├── taborder.lua ├── undoclose.lua ├── unique_instance.lua ├── userscripts.lua ├── vertical_tabs.lua ├── view_source.lua ├── viewpdf.lua ├── webinspector.lua ├── webview.lua ├── webview_wm.lua └── window.lua ├── log.c ├── log.h ├── luah.c ├── luah.h ├── luakit.1.in ├── luakit.c ├── resources └── icons │ ├── COPYING │ ├── tab-icon-chrome.png │ ├── tab-icon-chrome@2x.png │ ├── tab-icon-crash.png │ ├── tab-icon-crash@2x.png │ ├── tab-icon-error.png │ ├── tab-icon-error@2x.png │ ├── tab-icon-page.png │ ├── tab-icon-page@2x.png │ ├── tab-icon-private.png │ ├── tab-icon-private@2x.png │ ├── tab-icon-security-error.png │ └── tab-icon-security-error@2x.png ├── tests ├── async │ ├── run_test.lua │ ├── test_basic.lua │ ├── test_binds_api.lua │ ├── test_clib_luakit.lua │ ├── test_clib_regex.lua │ ├── test_clib_soup.lua │ ├── test_clib_sqlite3.lua │ ├── test_completion.lua │ ├── test_config.lua │ ├── test_http_test_server.lua │ ├── test_image_css.lua │ ├── test_lib_lousy_uri.lua │ ├── test_lib_lousy_util.lua │ ├── test_lua_files_load_successfully.lua │ ├── test_memory_leaks.lua │ ├── test_module_binds_have_descriptions.lua │ ├── test_scroll.lua │ ├── test_settings.lua │ ├── test_undoclose.lua │ ├── test_widget.lua │ └── wrangle_paths.lua ├── html │ ├── hello_world.html │ ├── image_css │ │ ├── default.html │ │ └── image.png │ ├── scroll.html │ └── undoclose_page.html ├── lib.lua ├── priv.lua ├── run_test.lua ├── style │ ├── test_common.lua │ ├── test_documentation.lua │ ├── test_luacheck.lua │ ├── test_source_format.lua │ └── test_widgets.lua └── util.c ├── web_context.c ├── web_context.h └── widgets ├── box.c ├── common.c ├── common.h ├── drawing_area.c ├── entry.c ├── eventbox.c ├── image.c ├── label.c ├── notebook.c ├── overlay.c ├── paned.c ├── scrolled.c ├── socket.c ├── spinner.c ├── webview.c ├── webview.h ├── webview ├── auth.c ├── downloads.c ├── find_controller.c ├── history.c ├── inspector.c ├── javascript.c ├── scroll.c └── stylesheets.c └── window.c /.gitattributes: -------------------------------------------------------------------------------- 1 | build-utils/getversion.sh export-subst 2 | *.c diff=cpp 3 | *.h diff=cpp 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Generated documentation 2 | doc/apidocs 3 | doc/html 4 | 5 | # Build targets 6 | luakit 7 | luakit.so 8 | luakit.1.gz 9 | tests/util.so 10 | 11 | # Generated source files 12 | common/tokenize.h 13 | common/tokenize.c 14 | buildopts.h 15 | 16 | # Intermediate build files 17 | *.o 18 | *.1 19 | 20 | # Miscellaneous 21 | *.swp 22 | *~ 23 | tags 24 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to luakit 2 | 3 | ## Submitting trivial fixes 4 | 5 | If you notice a small issue that's easy to fix, you're free to submut 6 | a pull request or patch directly, without asking or opening an issue 7 | first. This includes spelling / grammar mistakes, whitespace / 8 | formatting fixes, and any tweaks needed to get luakit to run. 9 | 10 | ## Submitting pull requests and patches 11 | 12 | If you plan to submit more involved patches, here's a checklist: 13 | 14 | 1. Unless you're contributing something you've already written, please 15 | open an issue to first discuss your plan; maintainers of luakit may have 16 | preferences about how you implement your goal or insights about needed 17 | changes. 18 | 19 | 2. Focus on a single goal at a time: 20 | - Do _not_ modify piece of code not related to your commit 21 | - Do _not_ include fixes for existing code-style problems; it's just adding noise for no gain 22 | 23 | 3. Ensure your commits are well-formed: 24 | - Make commits of logical units 25 | - Provide a meaningful commit message for each commit: the first line 26 | of the commit message should be a short description and should skip the 27 | full stop 28 | 29 | 4. Check for problems and formatting errors: 30 | - Ensure that your work does not cause any tests to fail 31 | - Add new tests if appropriate 32 | - Add an entry to the changelog if appropriate 33 | - Check for unnecessary whitespace with "git diff --check" before committing 34 | - Do not check in commented out code or unneeded files 35 | 36 | GitHub pull requests should be made against [https://github.com/luakit/luakit/](https://github.com/luakit/luakit/). 37 | -------------------------------------------------------------------------------- /build-utils/docgen/makedoc.lua: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env luajit 2 | 3 | local docgen_dir = "build-utils/" 4 | local config_path = "doc/docgen.ld" 5 | 6 | package.path = package.path .. ";" .. docgen_dir .. "?.lua" 7 | 8 | local parse = require "docgen.parse" 9 | local gen = require "docgen.gen" 10 | local find_files = require("find_files").find_files 11 | 12 | -- Load helpers 13 | 14 | local load_file = function (path) 15 | local f = assert(io.open(path, "r")) 16 | local contents = f:read("*all") 17 | f:close() 18 | return contents 19 | end 20 | 21 | local function load_config_ld (path) 22 | local code = load_file(path) 23 | local conf = assert(loadstring(code)) 24 | 25 | -- execute in sandbox 26 | local env = {} 27 | setfenv(conf, env) 28 | assert(pcall(conf)) 29 | return env 30 | end 31 | 32 | local parse_module_files = function (files) 33 | local docs = {} 34 | for _, filename in ipairs(files) do 35 | print("Parsing '" .. filename .. "'...") 36 | local parsed = parse.parse_file(filename) 37 | docs[#docs+1] = parsed 38 | end 39 | table.sort(docs, function(a, b) return a.name < b.name end) 40 | return docs 41 | end 42 | 43 | local parse_pages_files = function (files) 44 | local pages = {} 45 | for _, filename in ipairs(files) do 46 | print("Reading '" .. filename .. "'...") 47 | local text = load_file(filename) 48 | local name, idx = text:match("^@name (.-)\n()") 49 | filename = filename:gsub(".*/([%w-]+).md", "%1") 50 | assert(filename:gmatch("[%w-]+.md"), "Bad page filename " .. filename) 51 | pages[#pages+1] = { 52 | name = assert(name, "no @name line found"), 53 | filename = filename, 54 | text = text:sub(idx), 55 | } 56 | end 57 | table.sort(pages, function(a, b) return a.filename < b.filename end) 58 | return pages 59 | end 60 | 61 | --- 62 | 63 | local config = load_config_ld(config_path) 64 | local files = find_files(config.file, "%.lua$", config.file.exclude) 65 | 66 | local docs = parse_module_files(files) 67 | local pages = parse_pages_files(find_files(config.pages, "%.md$")) 68 | 69 | -- Split into modules and classes 70 | local module_docs = {} 71 | local class_docs = {} 72 | for _, doc in ipairs(docs) do 73 | if doc.module then table.insert(module_docs, doc) end 74 | if doc.class then table.insert(class_docs, doc) end 75 | end 76 | 77 | docs = { 78 | pages = pages, 79 | modules = module_docs, 80 | classes = class_docs, 81 | stylesheet = docgen_dir .. "docgen/style.css", 82 | } 83 | 84 | gen.generate_documentation(docs, config.dir) 85 | 86 | -- vim: et:sw=4:ts=8:sts=4:tw=80 87 | -------------------------------------------------------------------------------- /build-utils/docgen/process.lua: -------------------------------------------------------------------------------- 1 | assert(luakit, "This file must be run as a luakit config file") 2 | 3 | local find_files = require "build-utils.find_files" 4 | 5 | -- Restrict Lua search path to just the build dir for luakit-related files 6 | -- This is done by removing anything that looks like a luakit include dir 7 | local paths = { "./config/?.lua", "./lib/?.lua", "./lib/?/init.lua" } 8 | package.path:gsub("([^;]+)", function(path) 9 | if not path:find("/luakit/", 1, true) then 10 | table.insert(paths, path) 11 | end 12 | end) 13 | package.path = table.concat(paths, ";") 14 | 15 | require "window" 16 | require "webview" 17 | require "binds" 18 | local modes = require "modes" 19 | local lousy = require "lousy" 20 | 21 | local clear_all_mode_bindings = function () 22 | local mode_list = modes.get_modes() 23 | for mode_name in pairs(mode_list) do 24 | local mode = modes.get_mode(mode_name) 25 | mode.binds = nil 26 | end 27 | end 28 | 29 | local get_mode_bindings_for_module = function (mod) 30 | require(mod) 31 | clear_all_mode_bindings() 32 | package.loaded[mod] = nil 33 | require(mod) 34 | 35 | local ret = {} 36 | 37 | local mode_list = modes.get_modes() 38 | for mode_name in pairs(mode_list) do 39 | local mode = modes.get_mode(mode_name) 40 | ret[mode_name] = {} 41 | for _, b in pairs(mode.binds or {}) do 42 | table.insert(ret[mode_name], { 43 | name = lousy.bind.bind_to_string(b) or "???", 44 | desc = b.desc, 45 | }) 46 | end 47 | end 48 | 49 | return ret 50 | end 51 | 52 | local files = find_files.find_files({"lib/"}, ".+%.lua$", {"_wm%.lua$"}) 53 | 54 | local output = {} 55 | for _, file in ipairs(files) do 56 | local pkg = file:gsub("^%a+/", ""):gsub("%.lua$", ""):gsub("/", ".") 57 | output[pkg] = get_mode_bindings_for_module(pkg) 58 | end 59 | 60 | io.stdout:write(lousy.pickle.pickle(output)) 61 | 62 | luakit.quit() 63 | 64 | -- vim: et:sw=4:ts=8:sts=4:tw=80 65 | -------------------------------------------------------------------------------- /build-utils/getversion.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Get the current version using various methods. 3 | 4 | # The following will serve as a fallback version string (which is the short 5 | # hash of the latest commit before the application was packaged (if it was 6 | # packaged)). You will find that this file is listed inside the .gitattributes 7 | # file like so: 8 | # 9 | # ./build-utils/getversion.sh export-subst 10 | # 11 | # This tells git to replace the format string in the following line with the 12 | # current short hash upon the calling of the `git archive ` command. 13 | VERSION_FROM_ARCHIVE=9798a1d9b 14 | 15 | # The preferred method is to use the git describe command but this is only 16 | # possible if the .git directory is present. 17 | if [ -d .git -a -r .git ] 18 | then 19 | VERSION_FROM_GIT=$(git describe --tags --always) 20 | fi 21 | 22 | if [ x"$VERSION_FROM_GIT" != x ]; then 23 | echo $VERSION_FROM_GIT; exit 0; 24 | fi 25 | 26 | if [ "$VERSION_FROM_ARCHIVE" != ':%h$' ]; then 27 | echo $VERSION_FROM_ARCHIVE; exit 0; 28 | fi 29 | 30 | echo "ERROR: Commit hash detection failure. Dear packager, please figure out"\ 31 | "what has gone wrong and or get in touch with us." >&2 32 | 33 | exit 2 34 | 35 | # vim: ft=sh:et:sw=4:ts=8:sts=4:tw=80 36 | -------------------------------------------------------------------------------- /buildopts.h.in: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2016 Aidan Holm 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | * 17 | */ 18 | 19 | #ifndef LUAKIT_BUILDOPTS_H 20 | #define LUAKIT_BUILDOPTS_H 21 | 22 | /** Install location of luakit shared files. This serves as the base path for 23 | * all system Lua module loading paths. */ 24 | #define LUAKIT_INSTALL_PATH "/usr/local/share/luakit" 25 | 26 | /** Install location of default configuration files */ 27 | #define LUAKIT_CONFIG_PATH "/etc/xdg" 28 | 29 | /** Install location of luakit's documentation */ 30 | #define LUAKIT_DOC_PATH "/usr/local/share/luakit/doc" 31 | 32 | /** Install location of luakit's man pages */ 33 | #define LUAKIT_MAN_PATH "/usr/local/share/man" 34 | 35 | /** Install location of luakit's pixmaps */ 36 | #define LUAKIT_PIXMAP_PATH "/usr/local/share/pixmaps" 37 | 38 | /** Install location of luakit's application file */ 39 | #define LUAKIT_APP_PATH "/usr/local/share/applications" 40 | 41 | #endif 42 | 43 | // vim: ft=c:et:sw=4:ts=8:sts=4:tw=80 44 | -------------------------------------------------------------------------------- /clib/download.h: -------------------------------------------------------------------------------- 1 | /* 2 | * clib/download.h - WebKitDownload wrapper header 3 | * 4 | * Copyright © 2011 Fabian Streitel 5 | * Copyright © 2011 Mason Larobina 6 | * 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. 11 | * 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. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | * 20 | */ 21 | 22 | #ifndef LUAKIT_CLIB_DOWNLOAD_H 23 | #define LUAKIT_CLIB_DOWNLOAD_H 24 | 25 | #include 26 | #include 27 | 28 | void download_class_setup(lua_State*); 29 | gint luaH_download_push(lua_State*, WebKitDownload*); 30 | 31 | #endif 32 | 33 | // vim: ft=c:et:sw=4:ts=8:sts=4:tw=80 34 | -------------------------------------------------------------------------------- /clib/luakit.h: -------------------------------------------------------------------------------- 1 | /* 2 | * clib/luakit.h - Generic functions for Lua scripts 3 | * 4 | * Copyright © 2011 Mason Larobina 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #ifndef LUAKIT_CLIB_LUAKIT_H 22 | #define LUAKIT_CLIB_LUAKIT_H 23 | 24 | #include "common/luaclass.h" 25 | #include "common/ipc.h" 26 | 27 | #include 28 | 29 | void luakit_lib_setup(lua_State *L); 30 | void luaH_register_functions_on_endpoint(ipc_endpoint_t *ipc, lua_State *L); 31 | lua_class_t * luakit_lib_get_luakit_class(void); 32 | gint luaH_class_index_miss_property(lua_State *, lua_object_t *); 33 | gint luaH_class_newindex_miss_property(lua_State *, lua_object_t *); 34 | 35 | /* Referenced from deprecated webview:allow_certificate() */ 36 | gint luaH_luakit_allow_certificate(lua_State *L); 37 | 38 | #endif 39 | 40 | // vim: ft=c:et:sw=4:ts=8:sts=4:tw=80 41 | -------------------------------------------------------------------------------- /clib/msg.c: -------------------------------------------------------------------------------- 1 | /* 2 | * clib/msg.c - Lua logging interface 3 | * 4 | * Copyright © 2016 Aidan Holm 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #include "clib/msg.h" 22 | #include "common/clib/msg.h" 23 | 24 | /* setup luakit module signals */ 25 | static lua_class_t msg_class; 26 | LUA_CLASS_FUNCS(msg, msg_class) 27 | 28 | lua_class_t * 29 | msg_lib_get_msg_class(void) 30 | { 31 | return &msg_class; 32 | } 33 | 34 | void 35 | msg_lib_setup(lua_State *L) 36 | { 37 | static const struct luaL_Reg msg_lib[] = 38 | { 39 | LUA_CLASS_METHODS(msg) 40 | #define X(name) \ 41 | { #name, luaH_msg_##name }, 42 | LOG_LEVELS 43 | #undef X 44 | { NULL, NULL } 45 | }; 46 | 47 | luaH_openlib(L, "msg", msg_lib, msg_lib); 48 | 49 | msg_class.signals = signal_new(); 50 | 51 | /* Store ref to string.format() */ 52 | lua_getglobal(L, "string"); 53 | lua_getfield(L, -1, "format"); 54 | string_format_ref = luaH_object_ref(L, -1); 55 | lua_pop(L, 1); 56 | 57 | /* Store ref to tostring() */ 58 | lua_getglobal(L, "tostring"); 59 | tostring_ref = luaH_object_ref(L, -1); 60 | } 61 | 62 | // vim: ft=c:et:sw=4:ts=8:sts=4:tw=80 63 | -------------------------------------------------------------------------------- /clib/msg.h: -------------------------------------------------------------------------------- 1 | /* 2 | * clib/msg.h - Lua logging interface 3 | * 4 | * Copyright © 2016 Aidan Holm 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #ifndef LUAKIT_CLIB_MSG_H 22 | #define LUAKIT_CLIB_MSG_H 23 | 24 | #include 25 | #include "common/luaclass.h" 26 | 27 | void msg_lib_setup(lua_State *L); 28 | lua_class_t * msg_lib_get_msg_class(void); 29 | 30 | #endif 31 | 32 | // vim: ft=c:et:sw=4:ts=8:sts=4:tw=80 33 | -------------------------------------------------------------------------------- /clib/request.h: -------------------------------------------------------------------------------- 1 | /* 2 | * clib/request.h - WebKitRequest wrapper header 3 | * 4 | * Copyright © 2016 Aidan Holm 5 | * 6 | * Copyright © 2011 Fabian Streitel 7 | * Copyright © 2011 Mason Larobina 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | * 22 | */ 23 | 24 | #ifndef LUAKIT_CLIB_REQUEST_H 25 | #define LUAKIT_CLIB_REQUEST_H 26 | 27 | #include 28 | #include 29 | 30 | void request_class_setup(lua_State*); 31 | gint luaH_request_push_uri_scheme_request(lua_State*, WebKitURISchemeRequest*); 32 | 33 | #endif 34 | 35 | // vim: ft=c:et:sw=4:ts=8:sts=4:tw=80 36 | -------------------------------------------------------------------------------- /clib/soup.h: -------------------------------------------------------------------------------- 1 | /* 2 | * clib/soup.h - soup library 3 | * 4 | * Copyright © 2011 Mason Larobina 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #ifndef LUAKIT_CLIB_SOUP_H 22 | #define LUAKIT_CLIB_SOUP_H 23 | 24 | #include 25 | 26 | void soup_lib_setup(lua_State *L); 27 | 28 | #endif 29 | 30 | // vim: ft=c:et:sw=4:ts=8:sts=4:tw=80 31 | -------------------------------------------------------------------------------- /clib/sqlite3.h: -------------------------------------------------------------------------------- 1 | /* 2 | * clib/sqlite3.h - luakit sqlite3 wrapper 3 | * 4 | * Copyright © 2011 Mason Larobina 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #ifndef LUAKIT_CLIB_SQLITE3_H 22 | #define LUAKIT_CLIB_SQLITE3_H 23 | 24 | #include 25 | 26 | void sqlite3_class_setup(lua_State*); 27 | 28 | #endif 29 | 30 | // vim: ft=c:et:sw=4:ts=8:sts=4:tw=80 31 | -------------------------------------------------------------------------------- /clib/stylesheet.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2016 Aidan Holm 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | * 17 | */ 18 | 19 | #ifndef LUAKIT_CLIB_STYLESHEET_H 20 | #define LUAKIT_CLIB_STYLESHEET_H 21 | 22 | #include "common/luaobject.h" 23 | 24 | #include 25 | #include 26 | #include 27 | 28 | typedef struct { 29 | LUA_OBJECT_HEADER 30 | WebKitUserStyleSheet *stylesheet; 31 | gchar *source; 32 | } lstylesheet_t; 33 | 34 | void stylesheet_class_setup(lua_State *); 35 | gpointer luaH_checkstylesheet(lua_State *L, gint idx); 36 | 37 | /* Declared in widgets/webview/stylesheets.c */ 38 | void webview_stylesheets_regenerate_stylesheet(widget_t *w, lstylesheet_t *stylesheet); 39 | 40 | #endif 41 | 42 | // vim: ft=c:et:sw=4:ts=8:sts=4:tw=80 43 | -------------------------------------------------------------------------------- /clib/unique.h: -------------------------------------------------------------------------------- 1 | /* 2 | * clib/unique.c - libunique bindings for writing single instance 3 | * applications 4 | * 5 | * Copyright © 2011 Mason Larobina 6 | * 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. 11 | * 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. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | * 20 | */ 21 | 22 | #ifndef LUAKIT_CLIB_UNIQUE_H 23 | #define LUAKIT_CLIB_UNIQUE_H 24 | 25 | #include 26 | 27 | void unique_lib_setup(lua_State*); 28 | 29 | #endif /* #if LUAKIT_CLIB_UNIQUE_H */ 30 | 31 | // vim: ft=c:et:sw=4:ts=8:sts=4:tw=80 32 | -------------------------------------------------------------------------------- /clib/web_module.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2016 Aidan Holm 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | * 17 | */ 18 | 19 | #include "clib/web_module.h" 20 | #include "common/clib/ipc.h" 21 | 22 | static GPtrArray *required_web_modules; 23 | 24 | static int 25 | luaH_require_web_module(lua_State *L) 26 | { 27 | const char *name = luaL_checkstring(L, -1); 28 | g_ptr_array_add(required_web_modules, g_strdup(name)); 29 | 30 | /* Return an IPC channel with the same name for convenience */ 31 | return luaH_ipc_channel_new(L); 32 | } 33 | 34 | void 35 | web_module_load_modules_on_endpoint(ipc_endpoint_t *ipc) 36 | { 37 | for (unsigned i = 0; i < required_web_modules->len; i++) { 38 | const gchar *module_name = required_web_modules->pdata[i]; 39 | ipc_header_t header = { 40 | .type = IPC_TYPE_lua_require_module, 41 | .length = strlen(module_name)+1 42 | }; 43 | ipc_send(ipc, &header, module_name); 44 | } 45 | } 46 | 47 | void 48 | web_module_lib_setup(lua_State *L) 49 | { 50 | static const struct luaL_Reg web_module_methods[] = 51 | { 52 | { "__call", luaH_require_web_module }, 53 | { NULL, NULL } 54 | }; 55 | 56 | luaH_openlib(L, "require_web_module", web_module_methods, web_module_methods); 57 | 58 | required_web_modules = g_ptr_array_new(); 59 | } 60 | 61 | // vim: ft=c:et:sw=4:ts=8:sts=4:tw=80 62 | -------------------------------------------------------------------------------- /clib/web_module.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2016 Aidan Holm 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | * 17 | */ 18 | 19 | #ifndef LUAKIT_CLIB_WEB_MODULE_H 20 | #define LUAKIT_CLIB_WEB_MODULE_H 21 | 22 | #include "common/ipc.h" 23 | 24 | void web_module_lib_setup(lua_State *); 25 | void web_module_load_modules_on_endpoint(ipc_endpoint_t *ipc); 26 | 27 | #endif 28 | 29 | // vim: ft=c:et:sw=4:ts=8:sts=4:tw=80 30 | -------------------------------------------------------------------------------- /clib/xdg.h: -------------------------------------------------------------------------------- 1 | /* 2 | * clib/xdg.h - XDG Base Directory Specification paths 3 | * 4 | * Copyright © 2011 Mason Larobina 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #ifndef LUAKIT_CLIB_XDG_H 22 | #define LUAKIT_CLIB_XDG_H 23 | 24 | #include 25 | 26 | void xdg_lib_setup(lua_State*); 27 | 28 | #endif 29 | 30 | // vim: ft=c:et:sw=4:ts=8:sts=4:tw=80 31 | -------------------------------------------------------------------------------- /common/clib/ipc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2016 Aidan Holm 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | * 17 | */ 18 | 19 | #ifndef LUAKIT_COMMON_CLIB_IPC_H 20 | #define LUAKIT_COMMON_CLIB_IPC_H 21 | 22 | #include 23 | #include 24 | 25 | #include "common/util.h" 26 | #include "common/luaclass.h" 27 | #include "common/luaobject.h" 28 | 29 | typedef struct _ipc_channel_t { 30 | LUA_OBJECT_HEADER 31 | char *name; 32 | } ipc_channel_t; 33 | 34 | ipc_channel_t *luaH_check_ipc_channel(lua_State *L, gint idx); 35 | gint luaH_ipc_channel_new(lua_State *L); 36 | gint ipc_channel_send(lua_State *L); 37 | void ipc_channel_recv(lua_State *L, const gchar *arg, guint arglen); 38 | void ipc_channel_set_module(lua_State *L, const gchar *module_name); 39 | void ipc_channel_class_setup(lua_State *); 40 | 41 | #endif 42 | 43 | // vim: ft=c:et:sw=4:ts=8:sts=4:tw=80 44 | -------------------------------------------------------------------------------- /common/clib/luakit.h: -------------------------------------------------------------------------------- 1 | /* 2 | * common/clib/luakit.h - Generic functions for Lua scripts 3 | * 4 | * Copyright © 2016 Aidan Holm 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #ifndef LUAKIT_COMMON_CLIB_LUAKIT_H 22 | #define LUAKIT_COMMON_CLIB_LUAKIT_H 23 | 24 | #include 25 | #include 26 | #include 27 | 28 | #define LUAKIT_LIB_COMMON_METHODS \ 29 | { "time", luaH_luakit_time }, \ 30 | { "uri_encode", luaH_luakit_uri_encode }, \ 31 | { "uri_decode", luaH_luakit_uri_decode }, \ 32 | { "idle_add", luaH_luakit_idle_add }, \ 33 | { "idle_remove", luaH_luakit_idle_remove }, \ 34 | 35 | gint luaH_luakit_time(lua_State *L); 36 | gint luaH_luakit_uri_encode(lua_State *L); 37 | gint luaH_luakit_uri_decode(lua_State *L); 38 | gint luaH_luakit_idle_add(lua_State *L); 39 | gint luaH_luakit_idle_remove(lua_State *L); 40 | 41 | #endif 42 | 43 | // vim: ft=c:et:sw=4:ts=8:sts=4:tw=80 44 | -------------------------------------------------------------------------------- /common/clib/msg.h: -------------------------------------------------------------------------------- 1 | /* 2 | * common/clib/msg.h - Lua logging shared functionality 3 | * 4 | * Copyright © 2016 Aidan Holm 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #ifndef LUAKIT_COMMON_CLIB_MSG_H 22 | #define LUAKIT_COMMON_CLIB_MSG_H 23 | 24 | #include "luah.h" 25 | #include 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | static gpointer string_format_ref; 35 | static gpointer tostring_ref; 36 | 37 | static const gchar * 38 | luaH_msg_string_from_args(lua_State *L) 39 | { 40 | gint nargs = lua_gettop(L); 41 | /* Pre-convert all non-numerical arguments to strings */ 42 | for (gint i = 1; i <= nargs; ++i) { 43 | if (lua_type(L, i) != LUA_TNUMBER) { 44 | /* Convert to a string with tostring() ... */ 45 | luaH_object_push(L, tostring_ref); 46 | lua_pushvalue(L, i); 47 | lua_pcall(L, 1, 1, 0); 48 | /* ... And replace the original value */ 49 | lua_remove(L, i); 50 | lua_insert(L, i); 51 | } 52 | } 53 | luaH_object_push(L, string_format_ref); 54 | lua_insert(L, 1); 55 | if (lua_pcall(L, nargs, 1, 0)) 56 | luaL_error(L, "failed to format message: %s", lua_tostring(L, -1)); 57 | return lua_tostring(L, -1); 58 | } 59 | 60 | static gint 61 | luaH_msg(lua_State *L, log_level_t lvl) 62 | { 63 | lua_Debug ar; 64 | lua_getstack(L, 1, &ar); 65 | lua_getinfo(L, "Sln", &ar); 66 | /* Use .source if it's a file, since short_src is truncated for long paths */ 67 | const char *src = ar.source[0] == '@' ? ar.source+1 : ar.short_src; 68 | _log(lvl, src, "%s", luaH_msg_string_from_args(L)); 69 | return 0; 70 | } 71 | 72 | #define X(name) \ 73 | static gint \ 74 | luaH_msg_##name(lua_State *L) \ 75 | { \ 76 | return luaH_msg(L, LOG_LEVEL_##name); \ 77 | } \ 78 | 79 | LOG_LEVELS 80 | #undef X 81 | 82 | #endif 83 | 84 | // vim: ft=c:et:sw=4:ts=8:sts=4:tw=80 85 | -------------------------------------------------------------------------------- /common/clib/regex.h: -------------------------------------------------------------------------------- 1 | /* 2 | * common/clib/regex.h - Regex class header 3 | * 4 | * Copyright © 2010 Fabian Streitel 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #ifndef LUAKIT_COMMON_CLIB_REGEX_H 22 | #define LUAKIT_COMMON_CLIB_REGEX_H 23 | 24 | #include 25 | 26 | void regex_class_setup(lua_State *); 27 | 28 | #endif 29 | 30 | // vim: ft=c:et:sw=4:ts=8:sts=4:tw=80 31 | -------------------------------------------------------------------------------- /common/clib/timer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * common/clib/timer.h - Timer class header 3 | * 4 | * Copyright © 2010 Fabian Streitel 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #ifndef LUAKIT_COMMON_CLIB_TIMER_H 22 | #define LUAKIT_COMMON_CLIB_TIMER_H 23 | 24 | #include 25 | 26 | void timer_class_setup(lua_State *); 27 | 28 | #endif 29 | 30 | // vim: ft=c:et:sw=4:ts=8:sts=4:tw=80 31 | -------------------------------------------------------------------------------- /common/common.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2016 Aidan Holm 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | * 17 | */ 18 | 19 | #ifndef LUAKIT_COMMON_COMMON_H 20 | #define LUAKIT_COMMON_COMMON_H 21 | 22 | #include 23 | 24 | typedef struct _common_t { 25 | /** Main Lua VM state */ 26 | lua_State *L; 27 | } common_t; 28 | 29 | common_t common; 30 | 31 | #endif 32 | 33 | // vim: ft=c:et:sw=4:ts=8:sts=4:tw=80 34 | -------------------------------------------------------------------------------- /common/log.h: -------------------------------------------------------------------------------- 1 | /* 2 | * common/log.h - logging functions 3 | * 4 | * Copyright © 2016 Aidan Holm 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #ifndef LUAKIT_COMMON_LOG_H 22 | #define LUAKIT_COMMON_LOG_H 23 | 24 | #include 25 | #include 26 | 27 | #define LOG_LEVELS \ 28 | X(fatal) \ 29 | X(error) \ 30 | X(warn) \ 31 | X(info) \ 32 | X(verbose) \ 33 | X(debug) \ 34 | 35 | #define X(name) LOG_LEVEL_##name, 36 | typedef enum { LOG_LEVELS } log_level_t; 37 | #undef X 38 | 39 | /* ANSI term color codes */ 40 | #define ANSI_COLOR_RESET "\x1b[0m" 41 | 42 | #define ANSI_COLOR_BLACK "\x1b[30m" 43 | #define ANSI_COLOR_RED "\x1b[31m" 44 | #define ANSI_COLOR_GREEN "\x1b[32m" 45 | #define ANSI_COLOR_YELLOW "\x1b[33m" 46 | #define ANSI_COLOR_BLUE "\x1b[34m" 47 | #define ANSI_COLOR_MAGENTA "\x1b[35m" 48 | #define ANSI_COLOR_CYAN "\x1b[36m" 49 | #define ANSI_COLOR_GRAY "\x1b[37m" 50 | 51 | #define ANSI_COLOR_BG_RED "\x1b[41m" 52 | 53 | #define log(lvl, string, ...) _log(lvl, __FILE__, string, ##__VA_ARGS__) 54 | void _log(log_level_t lvl, const gchar *, const gchar *, ...) 55 | __attribute__ ((format (printf, 3, 4))); 56 | void va_log(log_level_t lvl, const gchar *, const gchar *, va_list); 57 | 58 | #define fatal(...) log(LOG_LEVEL_fatal, ##__VA_ARGS__) 59 | #define error(...) log(LOG_LEVEL_error, ##__VA_ARGS__) 60 | #define warn(...) log(LOG_LEVEL_warn, ##__VA_ARGS__) 61 | #define info(...) log(LOG_LEVEL_info, ##__VA_ARGS__) 62 | #define verbose(...) log(LOG_LEVEL_verbose, ##__VA_ARGS__) 63 | #define debug(...) log(LOG_LEVEL_debug, ##__VA_ARGS__) 64 | 65 | #endif 66 | 67 | // vim: ft=c:et:sw=4:ts=8:sts=4:tw=80 68 | -------------------------------------------------------------------------------- /common/luajs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2016 Aidan Holm 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | * 17 | */ 18 | 19 | #ifndef LUAKIT_COMMON_LUAJS_H 20 | #define LUAKIT_COMMON_LUAJS_H 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | gchar* tostring(JSContextRef context, JSValueRef value, gchar **error); 28 | gint luaJS_pushstring(lua_State *L, JSContextRef context, JSValueRef value, gchar **error); 29 | gint luaJS_pushobject(lua_State *L, JSContextRef context, JSObjectRef obj, gchar **error); 30 | gint luaJS_pushvalue(lua_State *L, JSContextRef context, JSValueRef value, gchar **error); 31 | JSValueRef luaJS_fromtable(lua_State *L, JSContextRef context, gint idx, gchar **error); 32 | JSValueRef luaJS_tovalue(lua_State *L, JSContextRef context, gint idx, gchar **error); 33 | JSValueRef luaJS_make_exception(JSContextRef context, const gchar *error); 34 | 35 | gint luaJS_eval_js(lua_State *L, JSContextRef context, const gchar *script, const gchar *source, bool no_return); 36 | 37 | #endif /* end of include guard: LUAKIT_COMMON_LUAJS_H */ 38 | 39 | // vim: ft=c:et:sw=4:ts=8:sts=4:tw=80 40 | -------------------------------------------------------------------------------- /common/luaserialize.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2016 Aidan Holm 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | * 17 | */ 18 | 19 | #ifndef LUAKIT_COMMON_LUASERIALIZE_H 20 | #define LUAKIT_COMMON_LUASERIALIZE_H 21 | 22 | #include 23 | #include 24 | 25 | void lua_serialize_range(lua_State *L, GByteArray *out, gint start, gint end); 26 | int lua_deserialize_range(lua_State *L, const guint8 *in, guint length); 27 | 28 | #endif 29 | 30 | // vim: ft=c:et:sw=4:ts=8:sts=4:tw=80 31 | -------------------------------------------------------------------------------- /common/luauniq.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2016 Aidan Holm 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | * 17 | */ 18 | 19 | #ifndef LUAKIT_COMMON_LUAUNIQ_H 20 | #define LUAKIT_COMMON_LUAUNIQ_H 21 | 22 | #include 23 | #include 24 | 25 | /* Registry system for unique Lua objects. 26 | * In contrast to the luaobject system, useful when a unique Lua instance is 27 | * owned by a C object, this system should be used when the C instance lifetime 28 | * depends on the Lua instance lifetime. 29 | */ 30 | 31 | void luaH_uniq_setup(lua_State *L, const gchar *reg, const gchar *mode); 32 | int luaH_uniq_add(lua_State *L, const gchar *reg, int k, int oud); 33 | int luaH_uniq_add_ptr(lua_State *L, const gchar *reg, gpointer key, int oud); 34 | int luaH_uniq_get(lua_State *L, const gchar *reg, int k); 35 | int luaH_uniq_get_ptr(lua_State *L, const gchar *reg, gpointer key); 36 | void luaH_uniq_del(lua_State *L, const gchar *reg, int k); 37 | void luaH_uniq_del_ptr(lua_State *L, const gchar *reg, gpointer key); 38 | 39 | #endif /* end of include guard: LUAKIT_COMMON_LUAUNIQ_H */ 40 | 41 | // vim: ft=c:et:sw=4:ts=8:sts=4:tw=80 42 | -------------------------------------------------------------------------------- /common/luautil.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2016 Aidan Holm 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | * 17 | */ 18 | 19 | #ifndef LUAKIT_COMMON_LUAUTIL_H 20 | #define LUAKIT_COMMON_LUAUTIL_H 21 | 22 | #include 23 | #include 24 | 25 | gint luaH_traceback(lua_State *L, lua_State *T, gint level); 26 | gint luaH_dofunction_on_error(lua_State *L); 27 | void luaH_add_paths(lua_State *L, const gchar *config_dir); 28 | gint luaH_push_gerror(lua_State *L, GError *error); 29 | gint luaH_push_strv(lua_State *L, const gchar * const *strv); 30 | const gchar ** luaH_checkstrv(lua_State *L, gint idx); 31 | 32 | #endif /* end of include guard: LUAKIT_COMMON_LUAUTIL_H */ 33 | 34 | // vim: ft=c:et:sw=4:ts=8:sts=4:tw=80 35 | -------------------------------------------------------------------------------- /common/luayield.h: -------------------------------------------------------------------------------- 1 | /* 2 | * common/luayield.h - Lua yield support 3 | * 4 | * Copyright © 2017 Aidan Holm 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #ifndef LUAKIT_COMMON_LUAYIELD_H 22 | #define LUAKIT_COMMON_LUAYIELD_H 23 | 24 | #include 25 | #include 26 | 27 | void luaH_yield_setup(lua_State *L); 28 | void luaH_yield_wrap_function(lua_State *L); 29 | int luaH_yield(lua_State *L); 30 | gboolean luaH_resume(lua_State *L, gint nret); 31 | 32 | #endif 33 | 34 | // vim: ft=c:et:sw=4:ts=8:sts=4:tw=80 35 | -------------------------------------------------------------------------------- /common/property.h: -------------------------------------------------------------------------------- 1 | /* 2 | * common/property.h - GObject property set/get lua functions 3 | * 4 | * Copyright © 2011 Mason Larobina 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #ifndef LUAKIT_COMMON_PROPERTY_H 22 | #define LUAKIT_COMMON_PROPERTY_H 23 | 24 | #include 25 | #include 26 | 27 | #include "common/tokenize.h" 28 | 29 | typedef enum { 30 | BOOL, 31 | CHAR, 32 | DOUBLE, 33 | FLOAT, 34 | INT, 35 | URI, 36 | } property_value_t; 37 | 38 | typedef union { 39 | gchar *c; 40 | gboolean b; 41 | gdouble d; 42 | gfloat f; 43 | gint i; 44 | } property_tmp_t; 45 | 46 | typedef struct { 47 | luakit_token_t tok; 48 | const gchar *name; 49 | property_value_t type; 50 | gboolean writable; 51 | } property_t; 52 | 53 | gint luaH_gobject_index(lua_State *, property_t *, luakit_token_t, GObject *); 54 | gboolean luaH_gobject_newindex(lua_State *, property_t *, luakit_token_t, 55 | gint, GObject *); 56 | 57 | #endif 58 | 59 | // vim: ft=c:et:sw=4:ts=8:sts=4:tw=80 60 | -------------------------------------------------------------------------------- /common/resource.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2017 Aidan Holm 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | * 17 | */ 18 | 19 | #include 20 | #include 21 | 22 | #include "buildopts.h" 23 | #include "common/resource.h" 24 | #include "common/log.h" 25 | 26 | static gchar *resource_path; 27 | static gchar **resource_paths; 28 | 29 | void 30 | resource_path_set(const gchar *path) 31 | { 32 | verbose("setting resource path '%s'", path); 33 | g_free(resource_path); 34 | resource_path = g_strdup(path); 35 | resource_paths = NULL; 36 | } 37 | 38 | gchar * 39 | resource_path_get() 40 | { 41 | return resource_path; 42 | } 43 | 44 | gchar * 45 | resource_find_file(const gchar *path) 46 | { 47 | g_assert(path); 48 | verbose("finding resource file '%s'", path); 49 | 50 | if (path[0] == '/') 51 | return g_strdup(path); 52 | 53 | if (!resource_paths) 54 | resource_paths = g_strsplit(resource_path, ";", 0); 55 | 56 | for (char **p = resource_paths; *p; p++) { 57 | gchar *full_path = g_build_filename(*p, path, NULL); 58 | if (access(full_path, R_OK)) 59 | debug("tried path '%s': %s", full_path, g_strerror(errno)); 60 | else { 61 | verbose("found resource file at '%s'", full_path); 62 | return full_path; 63 | } 64 | g_free(full_path); 65 | } 66 | 67 | verbose("no resource file found for '%s'", path); 68 | return NULL; 69 | } 70 | 71 | __attribute__((constructor)) static void 72 | resource_init(void) 73 | { 74 | resource_path = g_strdup("./resources;"LUAKIT_INSTALL_PATH"/resources"); 75 | } 76 | 77 | // vim: ft=c:et:sw=4:ts=8:sts=4:tw=80 78 | -------------------------------------------------------------------------------- /common/resource.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2017 Aidan Holm 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | * 17 | */ 18 | 19 | #ifndef LUAKIT_COMMON_RESOURCE_H 20 | #define LUAKIT_COMMON_RESOURCE_H 21 | 22 | #include 23 | 24 | void resource_path_set(const gchar *path); 25 | gchar *resource_path_get(); 26 | gchar *resource_find_file(const gchar *path); 27 | 28 | #endif 29 | 30 | // vim: ft=c:et:sw=4:ts=8:sts=4:tw=80 31 | -------------------------------------------------------------------------------- /common/util.c: -------------------------------------------------------------------------------- 1 | /* 2 | * common/util.c - useful functions 3 | * 4 | * Copyright © 2010 Mason Larobina 5 | * Copyright © 2007-2008 Julien Danjou 6 | * Copyright © 2006 Pierre Habouzit 7 | * 8 | * This program is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program. If not, see . 20 | * 21 | */ 22 | 23 | #include "common/util.h" 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | gboolean 31 | file_exists(const gchar *filename) 32 | { 33 | return (access(filename, F_OK) == 0); 34 | } 35 | 36 | /* Pretty-format calling function filename, function name & line number for 37 | * debugging purposes */ 38 | gchar* 39 | luaH_callerinfo(lua_State *L) 40 | { 41 | lua_Debug ar; 42 | 43 | /* get information about calling lua function */ 44 | if (lua_getstack(L, 1, &ar) && lua_getinfo(L, "Sln", &ar)) 45 | return g_strdup_printf("%s%s%s:%d", ar.short_src, 46 | ar.name ? ":" : "", ar.name ? ar.name : "", ar.currentline); 47 | 48 | return NULL; 49 | } 50 | 51 | gint 52 | luaH_panic(lua_State *L) 53 | { 54 | error("unprotected error in call to Lua API (%s)", lua_tostring(L, -1)); 55 | return 0; 56 | } 57 | 58 | gchar * 59 | strip_ansi_escapes(const gchar *in) 60 | { 61 | static GRegex *reg; 62 | 63 | if (!reg) { 64 | const gchar *expr = "[\\u001b\\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]"; 65 | GError *err = NULL; 66 | reg = g_regex_new(expr, G_REGEX_JAVASCRIPT_COMPAT | G_REGEX_DOTALL | G_REGEX_EXTENDED | G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, &err); 67 | g_assert_no_error(err); 68 | } 69 | 70 | return g_regex_replace_literal (reg, in, -1, 0, "", 0, NULL); 71 | } 72 | 73 | GQuark 74 | luakit_error_quark(void) 75 | { 76 | return g_quark_from_static_string("LuakitError"); 77 | } 78 | 79 | // vim: ft=c:et:sw=4:ts=8:sts=4:tw=80 80 | -------------------------------------------------------------------------------- /config/theme.lua: -------------------------------------------------------------------------------- 1 | -------------------------- 2 | -- Default luakit theme -- 3 | -------------------------- 4 | 5 | local theme = {} 6 | 7 | -- Default settings 8 | theme.font = "12px monospace" 9 | theme.fg = "#fff" 10 | theme.bg = "#000" 11 | 12 | -- Genaral colours 13 | theme.success_fg = "#0f0" 14 | theme.loaded_fg = "#33AADD" 15 | theme.error_fg = "#FFF" 16 | theme.error_bg = "#F00" 17 | 18 | -- Warning colours 19 | theme.warning_fg = "#F00" 20 | theme.warning_bg = "#FFF" 21 | 22 | -- Notification colours 23 | theme.notif_fg = "#444" 24 | theme.notif_bg = "#FFF" 25 | 26 | -- Menu colours 27 | theme.menu_fg = "#000" 28 | theme.menu_bg = "#fff" 29 | theme.menu_selected_fg = "#000" 30 | theme.menu_selected_bg = "#FF0" 31 | theme.menu_title_bg = "#fff" 32 | theme.menu_primary_title_fg = "#f00" 33 | theme.menu_secondary_title_fg = "#666" 34 | 35 | theme.menu_disabled_fg = "#999" 36 | theme.menu_disabled_bg = theme.menu_bg 37 | theme.menu_enabled_fg = theme.menu_fg 38 | theme.menu_enabled_bg = theme.menu_bg 39 | theme.menu_active_fg = "#060" 40 | theme.menu_active_bg = theme.menu_bg 41 | 42 | -- Proxy manager 43 | theme.proxy_active_menu_fg = '#000' 44 | theme.proxy_active_menu_bg = '#FFF' 45 | theme.proxy_inactive_menu_fg = '#888' 46 | theme.proxy_inactive_menu_bg = '#FFF' 47 | 48 | -- Statusbar specific 49 | theme.sbar_fg = "#fff" 50 | theme.sbar_bg = "#000" 51 | 52 | -- Downloadbar specific 53 | theme.dbar_fg = "#fff" 54 | theme.dbar_bg = "#000" 55 | theme.dbar_error_fg = "#F00" 56 | 57 | -- Input bar specific 58 | theme.ibar_fg = "#000" 59 | theme.ibar_bg = "rgba(0,0,0,0)" 60 | 61 | -- Tab label 62 | theme.tab_fg = "#888" 63 | theme.tab_bg = "#222" 64 | theme.tab_hover_bg = "#292929" 65 | theme.tab_ntheme = "#ddd" 66 | theme.selected_fg = "#fff" 67 | theme.selected_bg = "#000" 68 | theme.selected_ntheme = "#ddd" 69 | theme.loading_fg = "#33AADD" 70 | theme.loading_bg = "#000" 71 | 72 | theme.selected_private_tab_bg = "#3d295b" 73 | theme.private_tab_bg = "#22254a" 74 | 75 | -- Trusted/untrusted ssl colours 76 | theme.trust_fg = "#0F0" 77 | theme.notrust_fg = "#F00" 78 | 79 | -- General colour pairings 80 | theme.ok = { fg = "#000", bg = "#FFF" } 81 | theme.warn = { fg = "#F00", bg = "#FFF" } 82 | theme.error = { fg = "#FFF", bg = "#F00" } 83 | 84 | return theme 85 | 86 | -- vim: et:sw=4:ts=8:sts=4:tw=80 87 | -------------------------------------------------------------------------------- /doc/docgen.ld: -------------------------------------------------------------------------------- 1 | -- List of sources used to generate Lua API documentation 2 | -- Must be kept in sync with Makefile 3 | 4 | file = { 5 | "doc/luadoc", 6 | "lib", 7 | "common/clib", 8 | "tests/lib.lua", 9 | exclude = { 10 | "lib/markdown.lua", 11 | "lib/lousy/init.lua", 12 | "lib/lousy/widget/init.lua", 13 | }, 14 | } 15 | 16 | pages = { 17 | "doc/luadoc/pages/", 18 | } 19 | 20 | dir = "doc/apidocs" 21 | 22 | -- vim: et:sw=4:ts=8:sts=4:tw=80:ft=lua 23 | -------------------------------------------------------------------------------- /doc/luadoc/dom_document.lua: -------------------------------------------------------------------------------- 1 | --- Web process Lua interface to the DOM 2 | -- @class dom_document 3 | -- @author Aidan Holm 4 | -- @copyright 2017 Aidan Holm 5 | -- @prefix document 6 | -- 7 | -- DOCMACRO(available:web) 8 | -- 9 | -- # Retrieving the DOM document for a `page`: 10 | -- 11 | -- To retrieve the DOM document loaded in a page, use the @ref{page/document} property. 12 | 13 | --- @method create_element 14 | -- Create a new element for the DOM document. 15 | -- @tparam string tag_name The tag name of the element to create. 16 | -- @tparam[opt] table attributes A table of attributes to set on the new element. All keys and values must be strings. 17 | -- @tparam[opt] string inner_text The inner text to set on the element. 18 | 19 | --- @method element_from_point 20 | -- Find the DOM element at the given point. 21 | -- @tparam integer x The X coordinate of the point. 22 | -- @tparam integer y The Y coordinate of the point. 23 | -- @treturn dom_element The element at the given point. 24 | 25 | --- @property body 26 | -- The body of the DOM document. 27 | -- @type dom_element 28 | -- @readonly 29 | 30 | --- @property window.scroll_x 31 | -- The horizontal scroll position of the document view. 32 | -- @type integer 33 | -- @readonly 34 | 35 | --- @property window.scroll_y 36 | -- The vertical scroll position of the document view. 37 | -- @type integer 38 | -- @readonly 39 | 40 | --- @property window.inner_width 41 | -- The inner width of the DOM document. 42 | -- @type integer 43 | -- @readonly 44 | 45 | --- @property window.inner_height 46 | -- The inner height of the DOM document. 47 | -- @type integer 48 | -- @readonly 49 | 50 | -- vim: et:sw=4:ts=8:sts=4:tw=80 51 | -------------------------------------------------------------------------------- /doc/luadoc/ipc.lua: -------------------------------------------------------------------------------- 1 | --- IPC interface for communication between UI and Web processes. 2 | -- 3 | -- In Luakit there is a single UI Lua state, but there may be multiple web 4 | -- processes, each of which have a separate Lua state. This interface can be used 5 | -- to communicate between the UI and web processes. 6 | -- 7 | -- An interface similar to Luakit's signals handling is provided, and supports 8 | -- serializing multiple Lua parameters. 9 | -- 10 | -- -- In UI process 11 | -- local wm = require_web_module("test_wm") 12 | -- wm:add_signal("test", function (_, text) 13 | -- msg.info("Web process said %s!", text) 14 | -- end) 15 | -- 16 | -- -- In test_wm web module 17 | -- local ui = ipc_channel("test_wm") 18 | -- ui:emit_signal("test", "hello") 19 | -- 20 | -- @module ipc 21 | -- @author Aidan Holm 22 | -- @copyright 2016 Aidan Holm 23 | 24 | --- Open an IPC channel. 25 | -- 26 | -- Open an IPC channel and create an `ipc_channel` object. Signals 27 | -- emitted on this object on the web process will call signal handlers 28 | -- on the UI process, and vice versa. 29 | -- 30 | -- @function ipc_channel 31 | -- @tparam string name A name that identifies the channel. 32 | -- @treturn ipc_channel An IPC channel endpoint object. 33 | 34 | 35 | --- Require a Lua module on the web process. 36 | -- 37 | -- Load the named module on all web process Lua states. The module will 38 | -- be loaded on any future web process Lua states. 39 | -- 40 | -- For convenience, this function returns an IPC channel with the same name as 41 | -- the web module. 42 | -- 43 | -- @function require_web_module 44 | -- @tparam string name The name of the module to load. 45 | -- @treturn ipc_channel An IPC channel endpoint object. 46 | 47 | -- vim: et:sw=4:ts=8:sts=4:tw=80 48 | -------------------------------------------------------------------------------- /doc/luadoc/lousy.widget.lua: -------------------------------------------------------------------------------- 1 | --- Miscellaneous UI and statusbar widgets. 2 | -- 3 | -- This module provides a set of builtin user interface widgets used to 4 | -- construct the Luakit user interface, as well as a set of widgets that can be 5 | -- added to the luakit status bar. 6 | -- 7 | -- # Widget types: 8 | -- 9 | -- - `buf`: A status bar widget that displays the contents of the current key 10 | -- binding input buffer. When typing a multi-key key binding, such as `gi`, this 11 | -- widget will show the partially-typed key binding. 12 | -- - `hist`: A status bar widget that indicates whether the current tab can be 13 | -- navigated forwards or backwards. Backwards page history is indicated 14 | -- with a `+`, while forwards page history is indicated with a `-`. 15 | -- - `menu`: A widget that shows a scrollable menu. This widget type is 16 | -- used in the default luakit user interface. 17 | -- - `progress`: A status bar widget that shows the current page load 18 | -- progress as a percentage while a load is underway. The progress 19 | -- indicator is hidden when no page load is taking place. 20 | -- - `scroll`: A status bar widget that shows the current vertical scroll 21 | -- position of the current web page, as a percentage. 22 | -- - `ssl`: A status bar widget that shows whether the current web page was 23 | -- loaded over a secure connection. If the page was loaded securely, 24 | -- `(trust)` is shown in green; otherwise, `(notrust)` is shown in red. 25 | -- - `tabi`: A status bar that shows the number of the currently selected tab, 26 | -- as well as the total number of tabs in the window. 27 | -- - `tablist`: A widget that displays a set of `tab` widgets in a scrollable 28 | -- window. This widget type is used in the default luakit user interface. 29 | -- - `tablist`: A widget that displays the clickable "handle" attached to a tab. 30 | -- This widget type is used in the default luakit user interface. 31 | -- - `uri`: A status bar widget that displays the URI of the current web page. 32 | -- 33 | -- @module lousy.widget 34 | -- @author Aidan Holm 35 | -- @author Mason Larobina 36 | -- @copyright 2017 Aidan Holm 37 | -- @copyright 2010 Mason Larobina 38 | 39 | -- vim: et:sw=4:ts=8:sts=4:tw=80 40 | -------------------------------------------------------------------------------- /doc/luadoc/msg.lua: -------------------------------------------------------------------------------- 1 | --- Message logging support for Lua. 2 | -- 3 | -- This built-in library offers support for logging messages from Lua code. Five 4 | -- verbosity levels are available. By default, _verbose_ and _debug_ messages 5 | -- are not shown, but this can be changed when launching Luakit. 6 | -- 7 | -- All parameters are converted to strings. A newline is automatically appended. 8 | -- 9 | -- webview.add_signal("init", function (view) 10 | -- msg.debug("Opening a new web view <%d>", view.id) 11 | -- end) 12 | -- 13 | -- @module msg 14 | -- @copyright 2016 Aidan Holm 15 | 16 | --- Log a fatal error message, and abort the program. 17 | -- @function fatal 18 | -- @tparam string format Format string. 19 | -- @param ... Additional arguments referenced from the format string. 20 | 21 | --- Log a warning message. 22 | -- @function warn 23 | -- @tparam string format Format string. 24 | -- @param ... Additional arguments referenced from the format string. 25 | 26 | --- Log an informational message. 27 | -- @function info 28 | -- @tparam string format Format string. 29 | -- @param ... Additional arguments referenced from the format string. 30 | 31 | --- Log a verbose message. 32 | -- @function verbose 33 | -- @tparam string format Format string. 34 | -- @param ... Additional arguments referenced from the format string. 35 | 36 | --- Log a debug message. 37 | -- @function debug 38 | -- @tparam string format Format string. 39 | -- @param ... Additional arguments referenced from the format string. 40 | 41 | --- @signal log 42 | -- Emitted when a message is logged. This signal is not emitted for messages 43 | -- below the current log level. 44 | -- @tparam string level The level at which the message was logged. 45 | -- @tparam string group The origin of the message. 46 | -- @tparam string msg The message itself. May contain ANSI color escape codes. 47 | 48 | -- vim: et:sw=4:ts=8:sts=4:tw=80 49 | -------------------------------------------------------------------------------- /doc/luadoc/pages/06-tests.md: -------------------------------------------------------------------------------- 1 | @name Running the Test Suite 2 | #Running the Test Suite 3 | 4 | ##Test System 5 | 6 | Luakit's tests are currently divided into two main groups; *style* tests 7 | and *asynchronous* tests. Style tests check the Luakit source code for 8 | formatting consistency. Asynchronous tests run an isolated instance of 9 | Luakit with a special configuration file and run through a series of 10 | actions determined by the test case. 11 | 12 | ##Running Tests 13 | 14 | To run all of Luakit's tests, run `make run-tests`, or run the test 15 | runner directly with `./tests/run_test.lua`. This will run all tests in 16 | series. 17 | 18 | To run a subset of Luakit's tests, run the test runner with one 19 | or more directory/file-name prefixes as arguments. For example, 20 | `./tests/run_test.lua tests/style/` will run only the code style 21 | tests. Note that asynchronous tests are located in `tests/async/` (not 22 | `tests/asynchronous/`). 23 | 24 | ##Test API 25 | 26 | ###Style tests 27 | 28 | Style tests generally use the `tests.lib` function `find_files()` to 29 | retrieve a set of files of interest, before loading the contents of each 30 | file for examination. 31 | 32 | Reporting errors is done via the `tests.lib` function 33 | `format_file_errors()`. 34 | 35 | ###Asynchronous tests 36 | 37 | Each test file returns a table of test functions, keyed by test name. 38 | These are internally converted to coroutines, allowing test functions 39 | to be suspended and resumed. Test functions can access the `tests.lib` 40 | module, which contains several useful interfaces. 41 | -------------------------------------------------------------------------------- /doc/luadoc/regex.lua: -------------------------------------------------------------------------------- 1 | --- Regex support 2 | -- @class regex 3 | -- @author Aidan Holm 4 | -- @copyright 2017 Aidan Holm 5 | -- 6 | -- # Creating a new regex instance 7 | -- 8 | -- To create a new regex instance, use the `regex` constructor: 9 | -- 10 | -- local reg = regex{ pattern = "[1-9][0-9]*" } 11 | -- 12 | -- assert(reg:match("7392473")) 13 | 14 | --- @method match 15 | -- Scan a given string for a match. 16 | -- @tparam string string The string to scan for a match. 17 | -- @treturn boolean `true` if a match was found, `false` otherwise. 18 | 19 | -- vim: et:sw=4:ts=8:sts=4:tw=80 20 | -------------------------------------------------------------------------------- /doc/luadoc/soup.lua: -------------------------------------------------------------------------------- 1 | --- URI parsing utilities. 2 | -- 3 | -- DOCMACRO(available:ui) 4 | -- 5 | -- The soup API provides some utilities for parsing and converting URIs, written 6 | -- in C. For historical reasons, it also provides some other miscellaneous APIs. 7 | -- 8 | -- @module soup 9 | -- @author Mason Larobina 10 | -- @copyright 2012 Mason Larobina 11 | 12 | --- Parse a URI. 13 | -- @function parse_uri 14 | -- @tparam string uri The URI to parse. 15 | -- @treturn table A table of URI components. 16 | 17 | --- Convert a table of URI components to a string. 18 | -- @function uri_tostring 19 | -- @tparam table uri A table of URI components. 20 | -- @treturn string The URI string. 21 | 22 | --- The URI of the proxy to use for connections. Can be a URI, the 23 | -- string `"no_proxy"`, the string `"default"`, or `nil` (which means the same 24 | -- as `"default"`). 25 | -- @property proxy_uri 26 | -- @type string 27 | -- @readwrite 28 | -- @default `"default"` 29 | 30 | --- The cookie acceptance policy. Determines which cookies are accepted and 31 | -- stored. Can be one of `"always"`, `"never"`, and 32 | --`"no_third_party"`. 33 | -- @property accept_policy 34 | -- @type string 35 | -- @readwrite 36 | -- @default `"no_third_party"` 37 | 38 | --- The path to the cookie database to use. Should only be set once. Initially 39 | -- unset, meaning no cookie database will be used. 40 | -- @property cookies_storage 41 | -- @type string 42 | -- @readwrite 43 | -- @default `nil` 44 | 45 | -- vim: et:sw=4:ts=8:sts=4:tw=80 46 | -------------------------------------------------------------------------------- /doc/luadoc/sqlite3.lua: -------------------------------------------------------------------------------- 1 | --- Lightweight SQLite database interface. 2 | -- 3 | -- DOCMACRO(available:web) 4 | -- 5 | -- This module provides Lua access to SQLite databases. These are used 6 | -- for a number of purposes by the default modules, including storing 7 | -- user bookmarks, cookies, and browsing history. 8 | -- 9 | -- # Opening a database 10 | -- 11 | -- To create a new `sqlite3` instance and connect to a database, use the 12 | -- `sqlite3` constructor: 13 | -- 14 | -- local db = sqlite3{ filename = "path/to/database.db" } 15 | -- 16 | -- @class sqlite3 17 | -- @author Mason Larobina 18 | -- @copyright 2011 Mason Larobina 19 | 20 | --- @method exec 21 | -- 22 | -- Compile and execute the SQL query string `query` against the database. 23 | -- The `sqlite3` instance must have been opened successfully. 24 | -- 25 | -- @tparam string query A SQL query, comprised of one or more SQL statements. 26 | -- @tparam[opt] table bindings A table of values to bind to each SQL statement. 27 | -- @default `{}` 28 | -- @treturn table A table representing the query result. 29 | 30 | --- @method close 31 | -- Close a database and release related resources. 32 | 33 | --- @method compile 34 | -- Compile a SQL statement into a newly-created `sqlite3::statement` instance. 35 | -- @tparam string statement A SQL statement. 36 | -- @treturn sqlite3::statement A newly-created instance representing a compiled statement. 37 | 38 | --- @method changes 39 | -- Get the number of rows that were added, removed, or changed by the 40 | -- most recently executed `INSERT`, `UPDATE` or `DELETE` statement. 41 | -- @treturn number The number of modified rows. 42 | 43 | --- @property filename 44 | -- 45 | -- The path to the database that the `sqlite3` instance is connected to. 46 | -- 47 | -- @type string 48 | -- @readonly 49 | 50 | -- vim: et:sw=4:ts=8:sts=4:tw=80 51 | -------------------------------------------------------------------------------- /doc/luadoc/stylesheet.lua: -------------------------------------------------------------------------------- 1 | --- CSS stylesheet 2 | -- 3 | -- DOCMACRO(available:ui) 4 | -- 5 | -- Stylesheet objects allow Lua code to customize the appearance of web pages 6 | -- shown in `webview` widgets. The mozilla format (@-moz-document rules) is not 7 | -- supported. 8 | -- 9 | -- # Creating a new stylesheet 10 | -- 11 | -- To create a new stylesheet, use the `stylesheet` constructor: 12 | -- 13 | -- local style = stylesheet{ source = "#p { color: black; }" } 14 | -- 15 | -- # Modifying webview appearance 16 | -- 17 | -- To attach a `stylesheet` instance to a webview, modify the webview's 18 | -- @ref{stylesheets} table: 19 | -- 20 | -- local style = stylesheet{ ... } 21 | -- view.stylesheets[style] = true -- Enable the stylesheet 22 | -- 23 | -- @class stylesheet 24 | -- @author Aidan Holm 25 | -- @copyright 2016 Aidan Holm 26 | 27 | --- @property source 28 | -- The CSS source of the stylesheet. Modification will cause reapplication to any attached `webview` widgets. 29 | -- @type string 30 | -- @default `""` 31 | -- @readwrite 32 | 33 | -- vim: et:sw=4:ts=8:sts=4:tw=80 34 | -------------------------------------------------------------------------------- /doc/luadoc/timer.lua: -------------------------------------------------------------------------------- 1 | --- Timer support for Luakit. 2 | -- 3 | -- # Example usage: 4 | -- 5 | -- local t = timer{ interval = 500 } 6 | -- 7 | -- t:add_signal("timeout", function () 8 | -- print("500msec later!") 9 | -- end) 10 | -- 11 | -- t:start() 12 | -- 13 | -- @class timer 14 | -- @author Mason Larobina 15 | -- @copyright 2010 Mason Larobina 16 | 17 | --- @function __call 18 | -- Create a new timer instance. 19 | -- @tparam[opt] table properties Any initial timer properties to set. 20 | -- @default `{}` 21 | 22 | --- @method start 23 | -- Start a timer. 24 | -- 25 | -- The timer must already have an interval set. 26 | -- The timer should not already be running. 27 | 28 | --- @method stop 29 | -- Stop a timer. 30 | -- 31 | -- The timer should already be running. 32 | 33 | --- @property interval 34 | -- The interval of the timer, in milliseconds. 35 | -- @type integer 36 | -- @readwrite 37 | 38 | --- @property started 39 | -- Whether the timer is running. 40 | -- @type boolean 41 | -- @readonly 42 | -- @default `false` 43 | 44 | --- @signal timeout 45 | -- This signal is emitted when the time on the timer has expired. 46 | -- @tparam timer timer The timer that has expired. 47 | 48 | -- vim: et:sw=4:ts=8:sts=4:tw=80 49 | -------------------------------------------------------------------------------- /doc/luadoc/unique.lua: -------------------------------------------------------------------------------- 1 | --- Single instance support 2 | -- 3 | -- DOCMACRO(available:ui) 4 | -- 5 | -- This module allows Lua code to detect an already-running instance of 6 | -- luakit and open requested links on that instance, instead of opening 7 | -- two separate and independent instances. 8 | -- 9 | -- @module luakit.unique 10 | -- @author Mason Larobina 11 | -- @copyright 2011 Mason Larobina 12 | 13 | --- @function new 14 | -- Set up an application with a shared identifier used to locate 15 | -- already-running instances. This must be called before calling 16 | -- @ref{is_running} or @ref{send_message}. 17 | -- @tparam string id The application identifier string to use. 18 | 19 | --- @function is_running 20 | -- Check whether an application using the identifier previously given to 21 | -- `unique.new` is already running. 22 | -- @treturn boolean `true` if an application instance is already running. 23 | 24 | --- @function send_message 25 | -- Send a message (which must be a string) to the primary instance of 26 | -- the application. 27 | -- @tparam string message The message to send to the primary instance. 28 | 29 | --- @signal message 30 | -- Emitted only on the primary instance when a message is received from 31 | -- a secondary instance. 32 | -- @tparam string message The message sent with `unique.send_message()`. 33 | -- @tparam screen screen An opaque piece of data that represents the screen of 34 | -- the currently focused window of the main instance. 35 | 36 | -- vim: et:sw=4:ts=8:sts=4:tw=80 37 | -------------------------------------------------------------------------------- /doc/luadoc/widget.box.lua: -------------------------------------------------------------------------------- 1 | --- Box widget 2 | -- 3 | -- DOCMACRO(available:ui) 4 | -- 5 | -- The box widget allows stacking widgets horizontally or vertically. 6 | -- 7 | -- @class widget:box 8 | -- @prefix box 9 | -- @author Mason Larobina 10 | -- @copyright 2010 Mason Larobina 11 | 12 | --- @method pack 13 | -- Add a widget to the box. There are several valid options that can be set in 14 | -- an options table: 15 | -- 16 | -- - `from`: whether to add child to the start or the end of the box. Can be 17 | -- `"start"` or `"end"`. 18 | -- - `expand`: whether the new child should be assigned any extra space; such 19 | -- space is divided among all children with `expand` set to `true`. 20 | -- - `fill`: if `true`, the child will expand to fill any extra space assigned 21 | -- to it; otherwise, the child will be centered within the extra space. 22 | -- - `padding`: Extra space to put between the new child and its neighbors or 23 | -- the ends of the box widget, in pixels. 24 | -- @tparam widget child The widget to add as a new child. 25 | -- @tparam table|nil options Table of options. 26 | 27 | --- @method reorder_child 28 | -- Rearrange a widget already in the box. 29 | -- @tparam widget child The child widget to reorder. 30 | -- @tparam integer position The position to move the widget to. 31 | 32 | --- @property homogeneous 33 | -- Whether the child widgets should all have the same size. 34 | -- @type boolean 35 | -- @readwrite 36 | -- @default `false` 37 | 38 | --- @property spacing 39 | -- The amount of space between each of the child widgets. Must be non-negative. 40 | -- @type number 41 | -- @readwrite 42 | -- @default 0 43 | 44 | --- @property bg 45 | -- The background color of the box widget. 46 | -- @type string|nil 47 | -- @readwrite 48 | 49 | -- vim: et:sw=4:ts=8:sts=4:tw=80 50 | -------------------------------------------------------------------------------- /doc/luadoc/widget.drawing_area.lua: -------------------------------------------------------------------------------- 1 | --- Drawing area widget 2 | -- 3 | -- DOCMACRO(available:ui) 4 | -- 5 | -- The drawing area widget allows drawing from Cairo via the LuaJIT FFI. 6 | -- 7 | -- Widgets of this type cannot be created without LuaJIT FFI support. 8 | -- 9 | -- @class widget:drawing_area 10 | -- @prefix area 11 | -- @author Aidan Holm 12 | -- @copyright 2017 Aidan Holm 13 | 14 | --- @method invalidate 15 | -- Invalidates the drawing area and queues a redraw. 16 | 17 | --- @signal draw 18 | -- This signal is emitted when the contents of the drawing area need to be 19 | -- redrawn, using the provided Cairo drawing context. 20 | -- @tparam cairo context A FFI wrapper to a `cairo_t *` type. 21 | 22 | -- vim: et:sw=4:ts=8:sts=4:tw=80 23 | -------------------------------------------------------------------------------- /doc/luadoc/widget.entry.lua: -------------------------------------------------------------------------------- 1 | --- Single-line text entry widget 2 | -- 3 | -- DOCMACRO(available:ui) 4 | -- 5 | -- The entry widget shows a text box for single-line user input. 6 | -- 7 | -- @class widget:entry 8 | -- @prefix entry 9 | -- @author Mason Larobina 10 | -- @copyright 2010 Mason Larobina 11 | 12 | --- @property position 13 | -- The position of the caret within the entry widget. 14 | -- @type integer 15 | -- @readwrite 16 | 17 | --- @property text 18 | -- The contents of the entry widget. 19 | -- @type string 20 | -- @readwrite 21 | 22 | --- @property fg 23 | -- The color of the text within the entry widget. 24 | -- @type string 25 | -- @readwrite 26 | 27 | --- @property bg 28 | -- The background color of the entry widget. 29 | -- @type string 30 | -- @readwrite 31 | 32 | --- @property font 33 | -- The font to use to display the text within the entry widget. 34 | -- @type string 35 | -- @readwrite 36 | 37 | --- @property show_frame 38 | -- Whether the frame surrounding the entry widget should be shown. 39 | -- @type boolean 40 | -- @readwrite 41 | 42 | --- @method insert 43 | -- Insert text into the entry widget. 44 | -- @tparam[opt] integer position Optional position at which to insert text. 45 | -- Defaults to inserting at the end of any text already in the entry widget. 46 | -- @tparam string text The text to insert. 47 | 48 | --- @method select_region 49 | -- Select some or all of the text within the entry widget. 50 | -- @tparam integer startpos The start of the region. 51 | -- @tparam[opt] integer startpos The end of the region. Defaults to the end of 52 | -- the text in the entry widget. 53 | 54 | --- @signal activate 55 | -- Emitted when the entry widget is activated by pressing the `Enter` key. 56 | 57 | --- @signal changed 58 | -- Emitted when the text within the entry widget changes. 59 | 60 | --- @signal property::position 61 | -- Emitted when the position of the caret within the entry widget changes. 62 | 63 | --- @signal key-press 64 | -- Emitted when a key is pressed while the entry widget has the input focus. 65 | -- @tparam table modifiers An array of strings, one for each modifier key held. 66 | -- @tparam string key The key that was pressed, if printable, or a keysym 67 | -- otherwise. 68 | -- @treturn boolean `true` if the event has been handled and should not be 69 | -- propagated further. 70 | 71 | -- vim: et:sw=4:ts=8:sts=4:tw=80 72 | -------------------------------------------------------------------------------- /doc/luadoc/widget.event_box.lua: -------------------------------------------------------------------------------- 1 | --- Event Box widget 2 | -- 3 | -- DOCMACRO(available:ui) 4 | -- 5 | -- The event box widget allows stacking widgets horizontally or vertically. 6 | -- 7 | -- @class widget:event_box 8 | -- @prefix ebox 9 | -- @author Mason Larobina 10 | -- @copyright 2010 Mason Larobina 11 | 12 | --- @property bg 13 | -- The background color of the box widget. 14 | -- @type string|nil 15 | -- @readwrite 16 | 17 | --- @signal add 18 | -- Emitted when a new widget is set as this widget's child. 19 | -- @tparam widget child The new child widget. 20 | 21 | --- @signal button-press 22 | -- Emitted when a mouse button was pressed with the cursor inside the event box widget. 23 | -- 24 | -- @tparam table modifiers An array of strings, one for each modifier key held 25 | -- at the time of the event. 26 | -- @tparam integer button The number of the button pressed, beginning 27 | -- from `1`; i.e. `1` corresponds to the left mouse button. 28 | -- @treturn boolean `true` if the event has been handled and should not be 29 | -- propagated further. 30 | 31 | --- @signal button-release 32 | -- Emitted when a mouse button was released with the cursor inside the event box widget. 33 | -- 34 | -- @tparam table modifiers An array of strings, one for each modifier key held 35 | -- at the time of the event. 36 | -- @tparam integer button The number of the button pressed, beginning 37 | -- from `1`; i.e. `1` corresponds to the left mouse button. 38 | -- @treturn boolean `true` if the event has been handled and should not be 39 | -- propagated further. 40 | 41 | --- @signal button-double-click 42 | -- Emitted when a mouse button was double-clicked with the cursor inside the event box widget. 43 | -- 44 | -- @tparam table modifiers An array of strings, one for each modifier key held 45 | -- at the time of the event. 46 | -- @tparam integer button The number of the button pressed, beginning 47 | -- from `1`; i.e. `1` corresponds to the left mouse button. 48 | -- @treturn boolean `true` if the event has been handled and should not be 49 | -- propagated further. 50 | 51 | --- @signal mouse-enter 52 | -- Emitted when the mouse cursor enters the event box widget. 53 | -- @tparam table modifiers An array of strings, one for each modifier key held. 54 | -- @treturn boolean `true` if the event has been handled and should not be 55 | -- propagated further. 56 | 57 | --- @signal mouse-leave 58 | -- Emitted when the mouse cursor leaves the event box widget. 59 | -- @tparam table modifiers An array of strings, one for each modifier key held. 60 | -- @treturn boolean `true` if the event has been handled and should not be 61 | -- propagated further. 62 | 63 | -- vim: et:sw=4:ts=8:sts=4:tw=80 64 | -------------------------------------------------------------------------------- /doc/luadoc/widget.image.lua: -------------------------------------------------------------------------------- 1 | --- Image widget 2 | -- 3 | -- DOCMACRO(available:ui) 4 | -- 5 | -- The image widget shows an image from a website favicon, a file, or an icon 6 | -- name. 7 | -- 8 | -- @class widget:image 9 | -- @prefix image 10 | -- @author Aidan Holm 11 | -- @copyright 2016 Aidan Holm 12 | 13 | --- @method filename 14 | -- Show an image from a file. On HiDPI screens, a file with "@2x" before 15 | -- the extension will be used instead, if it is present. 16 | -- 17 | -- The filename is used to search the directories specified by @ref{luakit/resource_path}. 18 | -- @tparam string path The path to the image file. 19 | 20 | --- @method icon 21 | -- Show a named icon. 22 | -- @tparam string name The name of the icon to use. 23 | -- @tparam integer size The size at which to display the icon, in pixels; must be one of 24 | -- 16, 24, 32, or 48. 25 | 26 | --- @method scale 27 | -- Scale the current image to a certain size. 28 | -- @tparam integer width The width to scale to, in pixels. 29 | -- @tparam[opt] integer height The height to scale to, in pixels. If omitted, the desired width is used for the height as well. 30 | 31 | --- @method set_favicon_for_uri 32 | -- Show the favicon for the given URI, if it has one, at a size of 16x16 pixels. 33 | -- @tparam string uri The URI. 34 | -- @treturn boolean `true` if the favicon was successfully shown. 35 | 36 | -- vim: et:sw=4:ts=8:sts=4:tw=80 37 | -------------------------------------------------------------------------------- /doc/luadoc/widget.label.lua: -------------------------------------------------------------------------------- 1 | --- Label widget 2 | -- 3 | -- DOCMACRO(available:ui) 4 | -- 5 | -- The label widget shows a single line of formatted text. It is not editable by the 6 | -- user. 7 | -- 8 | -- @class widget:label 9 | -- @prefix label 10 | -- @author Mason Larobina 11 | -- @copyright 2010 Mason Larobina 12 | 13 | --- @property padding 14 | -- The widget padding. Table has two fields, `x` and `y`, representing the 15 | -- vertical and horizontal padding respectively, in pixels. 16 | -- 17 | -- Available only for older versions of GTK (< 2.14). 18 | -- @type table 19 | -- @readwrite 20 | 21 | --- @property align 22 | -- The text alignment. Table has two fields, `x` and `y`, representing the 23 | -- vertical and horizontal alignment respectively. Values should be between 24 | -- 0--1, where 0 means aligned to the left/top, and 1 means aligned to the 25 | -- right/bottom. 26 | -- @type table 27 | -- @readwrite 28 | 29 | --- @property text 30 | -- Text to display in the widget. This property uses Pango markup. 31 | -- @type string 32 | -- @readwrite 33 | 34 | --- @property fg 35 | -- The color of the text displayed by the widget. This can be changed with 36 | -- markup set by the @ref{widget:label/text} property. 37 | -- @type string 38 | -- @readwrite 39 | 40 | --- @property bg 41 | -- The background color of the label widget. 42 | -- @type string 43 | -- @readwrite 44 | 45 | --- @property font 46 | -- The font to use to display the label text. 47 | -- @type string 48 | -- @readwrite 49 | 50 | --- @property selectable 51 | -- Whether the text can be selected by dragging with the mouse cursor. 52 | -- @type boolean 53 | -- @readwrite 54 | -- @default `false` 55 | 56 | --- @property textwidth 57 | -- The desired width of the label, in characters. 58 | -- @type integer 59 | -- @readwrite 60 | 61 | --- @signal key-press 62 | -- Emitted when a key is pressed while the label widget has the input focus. 63 | -- @tparam table modifiers An array of strings, one for each modifier key held. 64 | -- @tparam string key The key that was pressed, if printable, or a keysym 65 | -- otherwise. 66 | -- @treturn boolean `true` if the event has been handled and should not be 67 | -- propagated further. 68 | 69 | -- vim: et:sw=4:ts=8:sts=4:tw=80 70 | -------------------------------------------------------------------------------- /doc/luadoc/widget.overlay.lua: -------------------------------------------------------------------------------- 1 | --- Overlay widget 2 | -- 3 | -- DOCMACRO(available:ui) 4 | -- 5 | -- The overlay widget allows independent layers of widgets. 6 | -- 7 | -- @class widget:overlay 8 | -- @prefix overlay 9 | -- @author Mason Larobina 10 | -- @copyright 2010 Mason Larobina 11 | 12 | --- @method pack 13 | -- Add a widget to the overlay; it will be stacked on top of the main child 14 | -- widget. Multiple overlaying widgets can be added; their order affects the 15 | -- order in which they will be rendered, if they overlap. 16 | -- 17 | -- The options table has two keys that can be set: `halign` and `valign`. There 18 | -- are five possible values for these keys: 19 | -- 20 | -- - `fill`: expand the new child widget to fill the total available area. 21 | -- - `start`: align the new child widget to the left/top. 22 | -- - `end`: align the new child widget to the right/bottom. 23 | -- - `center`: align the new child widget to the center. 24 | -- - `baseline`: align according to the child widget's baseline. Only works for `valign`. 25 | -- 26 | -- @tparam widget child The widget to add as a new child. 27 | -- @tparam table|nil options Table of options. 28 | 29 | --- @method reorder_child 30 | -- Reorder a widget already in the overlay. The order affects draw order and 31 | -- focus order. 32 | -- @tparam widget child The child widget to reorder. 33 | -- @tparam integer position The position to move the widget to. 34 | 35 | -- vim: et:sw=4:ts=8:sts=4:tw=80 36 | -------------------------------------------------------------------------------- /doc/luadoc/widget.paned.lua: -------------------------------------------------------------------------------- 1 | --- Paned widget 2 | -- 3 | -- DOCMACRO(available:ui) 4 | -- 5 | -- The paned widget provides a two-pane interface widget, with a 6 | -- draggable slider between panes. 7 | -- 8 | -- @class widget:paned 9 | -- @prefix paned 10 | -- @author Mason Larobina 11 | -- @copyright 2010 Mason Larobina 12 | 13 | --- @method pack1 14 | -- Add a widget to the left/top panel. There are two options that can be set: 15 | -- 16 | -- - `resize`: whether the new child widget should be resized as the 17 | -- pane is resized. 18 | -- - `shrink`: whether the new child widget should be shrunk smaller 19 | -- than its default size. 20 | -- 21 | -- @tparam widget child The widget to add as a new child. 22 | -- @tparam table|nil options Table of options. 23 | 24 | --- @method pack2 25 | -- Add a widget to the right/bottom panel. Otherwise the same as `pack1()`. 26 | -- @tparam widget child The widget to add as a new child. 27 | -- @tparam table|nil options Table of options. 28 | 29 | --- @property top 30 | -- The top/left pane child widget. 31 | -- @type widget 32 | -- @readonly 33 | 34 | --- @property left 35 | -- The top/left pane child widget. 36 | -- @type widget 37 | -- @readonly 38 | 39 | --- @property bottom 40 | -- The bottom/right pane child widget. 41 | -- @type widget 42 | -- @readonly 43 | 44 | --- @property right 45 | -- The bottom/right pane child widget. 46 | -- @type widget 47 | -- @readonly 48 | 49 | --- @property position 50 | -- The current position of the divider, in pixels. 51 | -- @type number 52 | -- @readwrite 53 | 54 | -- vim: et:sw=4:ts=8:sts=4:tw=80 55 | -------------------------------------------------------------------------------- /doc/luadoc/widget.scrolled.lua: -------------------------------------------------------------------------------- 1 | --- Scrolling wrapper widget 2 | -- 3 | -- DOCMACRO(available:ui) 4 | -- 5 | -- The scrolled widget allows widgets too big to fit within a desired region to 6 | -- be scrolled. One example use for this is the tablist, which will be scrolled 7 | -- when there are too many tabs to display all at once. 8 | -- 9 | -- @class widget:scrolled 10 | -- @prefix scrolled 11 | -- @author Mason Larobina 12 | -- @copyright 2010 Mason Larobina 13 | 14 | --- @property scrollbars 15 | -- The scrollbar policy. Two fields, `h` and `v`, specify the scrollbar policy 16 | -- for horizontal and vertical scrollbars respectively. They can have values of 17 | -- `"always"`, `"auto"`, `"never"`, or `"external"`. 18 | -- @type table 19 | -- @readwrite 20 | 21 | --- @property scroll 22 | -- The current scroll position. Two fields, `h` and `v`, specify the scroll 23 | -- offset from the left and top respectively, in pixels. 24 | -- @type table 25 | -- @readwrite 26 | 27 | -- vim: et:sw=4:ts=8:sts=4:tw=80 28 | -------------------------------------------------------------------------------- /doc/luadoc/widget.socket.lua: -------------------------------------------------------------------------------- 1 | --- Socket widget 2 | -- 3 | -- DOCMACRO(available:ui) 4 | -- 5 | -- The socket widget allows displaying a window from an XEMBED client within the 6 | -- luakit user interface. 7 | -- 8 | -- @class widget:socket 9 | -- @prefix socket 10 | -- @author Mason Larobina 11 | -- @copyright 2010 Mason Larobina 12 | 13 | --- @property id 14 | -- When reading, this returns the window ID of this socket widget. 15 | -- When writing, this adds an XEMBED client with the given window ID to the 16 | -- socket. 17 | -- @type integer 18 | -- @readwrite 19 | 20 | --- @property plugged 21 | -- Whether a client window is currently plugged into this socket. 22 | -- @type boolean 23 | -- @readonly 24 | 25 | --- @signal plug-added 26 | -- Emitted when a client window is added to the socket. 27 | 28 | --- @signal plug-removed 29 | -- Emitted when a client window is removed from the socket. 30 | 31 | -- vim: et:sw=4:ts=8:sts=4:tw=80 32 | -------------------------------------------------------------------------------- /doc/luadoc/widget.spinner.lua: -------------------------------------------------------------------------------- 1 | --- Spinner widget 2 | -- 3 | -- DOCMACRO(available:ui) 4 | -- 5 | -- The spinner widget indicates an ongoing process of indefinite duration. 6 | -- 7 | -- @class widget:spinner 8 | -- @prefix spinner 9 | -- @author Mason Larobina 10 | -- @copyright 2010 Mason Larobina 11 | 12 | --- @method start 13 | -- Start spinning. 14 | 15 | --- @method stop 16 | -- Stop spinning. 17 | 18 | --- @property started 19 | -- Whether the widget is spinning. 20 | -- @type boolean 21 | -- @readonly 22 | 23 | -- vim: et:sw=4:ts=8:sts=4:tw=80 24 | -------------------------------------------------------------------------------- /extension/clib/dom_document.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2016 Aidan Holm 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | * 17 | */ 18 | 19 | #ifndef LUAKIT_EXTENSION_CLIB_DOM_DOCUMENT_H 20 | #define LUAKIT_EXTENSION_CLIB_DOM_DOCUMENT_H 21 | 22 | #include 23 | 24 | #include "common/util.h" 25 | #include "common/luaclass.h" 26 | #include "common/luaobject.h" 27 | 28 | #include 29 | 30 | typedef struct _dom_document_t { 31 | LUA_OBJECT_HEADER 32 | WebKitDOMDocument *document; 33 | } dom_document_t; 34 | 35 | void dom_document_class_setup(lua_State *); 36 | gint luaH_dom_document_from_webkit_dom_document(lua_State *L, WebKitDOMDocument *doc); 37 | gint luaH_dom_document_from_web_page(lua_State *L, WebKitWebPage *web_page); 38 | 39 | #endif 40 | 41 | // vim: ft=c:et:sw=4:ts=8:sts=4:tw=80 42 | -------------------------------------------------------------------------------- /extension/clib/dom_element.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2016 Aidan Holm 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | * 17 | */ 18 | 19 | #ifndef LUAKIT_EXTENSION_CLIB_DOM_ELEMENT_H 20 | #define LUAKIT_EXTENSION_CLIB_DOM_ELEMENT_H 21 | 22 | #include "extension/extension.h" 23 | 24 | #include "common/util.h" 25 | #include "common/luaclass.h" 26 | #include "common/luaobject.h" 27 | #include "extension/clib/page.h" 28 | 29 | #include 30 | 31 | typedef struct _dom_element_t { 32 | LUA_OBJECT_HEADER 33 | WebKitDOMElement *element; 34 | } dom_element_t; 35 | 36 | void dom_element_class_setup(lua_State *); 37 | gint luaH_dom_element_from_node(lua_State *L, WebKitDOMElement* node); 38 | JSValueRef dom_element_js_ref(page_t *page, dom_element_t *element); 39 | dom_element_t * luaH_to_dom_element(lua_State *L, gint idx); 40 | 41 | #endif 42 | 43 | // vim: ft=c:et:sw=4:ts=8:sts=4:tw=80 44 | -------------------------------------------------------------------------------- /extension/clib/ipc.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2016 Aidan Holm 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | * 17 | */ 18 | 19 | #include "extension/ipc.h" 20 | #include "extension/extension.h" 21 | #include "extension/clib/page.h" 22 | #include "common/clib/ipc.h" 23 | #include "common/luaserialize.h" 24 | 25 | #define REG_KEY "luakit.registry.ipc_channel" 26 | 27 | gint 28 | ipc_channel_send(lua_State *L) 29 | { 30 | ipc_channel_t *ipc_channel = luaH_check_ipc_channel(L, 1); 31 | luaL_checkstring(L, 2); 32 | lua_pushstring(L, ipc_channel->name); 33 | ipc_send_lua(extension.ipc, IPC_TYPE_lua_ipc, L, 2, lua_gettop(L)); 34 | return 0; 35 | } 36 | 37 | void 38 | ipc_channel_recv(lua_State *L, const gchar *arg, guint arglen) 39 | { 40 | gint top = lua_gettop(L); 41 | int n = lua_deserialize_range(L, (guint8*)arg, arglen); 42 | 43 | /* Remove signal name, module_name and page_id from the stack */ 44 | const char *signame = lua_tostring(L, -n); 45 | lua_remove(L, -n); 46 | const char *module_name = lua_tostring(L, -2); 47 | guint64 page_id = lua_tointeger(L, -1); 48 | lua_pop(L, 2); 49 | n -= 3; 50 | 51 | /* Prepend the page object, or nil */ 52 | if (page_id) { 53 | WebKitWebPage *web_page = webkit_web_extension_get_page(extension.ext, page_id); 54 | luaH_page_from_web_page(L, web_page); 55 | } else 56 | lua_pushnil(L); 57 | lua_insert(L, -n-1); 58 | n++; 59 | 60 | /* Push the right module object onto the stack */ 61 | lua_pushstring(L, REG_KEY); 62 | lua_rawget(L, LUA_REGISTRYINDEX); 63 | lua_pushstring(L, module_name); 64 | lua_rawget(L, -2); 65 | lua_remove(L, -2); 66 | 67 | /* Move the module before arguments, and emit signal */ 68 | if (!lua_isnil(L, -1)) { 69 | lua_insert(L, -n-1); 70 | luaH_object_emit_signal(L, -n-1, signame, n, 0); 71 | } 72 | lua_settop(L, top); 73 | } 74 | 75 | // vim: ft=c:et:sw=4:ts=8:sts=4:tw=80 76 | -------------------------------------------------------------------------------- /extension/clib/luakit.h: -------------------------------------------------------------------------------- 1 | /* 2 | * extension/clib/luakit.h - Generic functions for Lua scripts 3 | * 4 | * Copyright © 2011 Mason Larobina 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #ifndef LUAKIT_EXTENSION_CLIB_LUAKIT_H 22 | #define LUAKIT_EXTENSION_CLIB_LUAKIT_H 23 | 24 | #include "common/luaclass.h" 25 | #include "common/ipc.h" 26 | 27 | void luakit_lib_setup(lua_State *L); 28 | void luakit_lib_emit_pending_signals(lua_State *L); 29 | 30 | #endif 31 | 32 | // vim: ft=c:et:sw=4:ts=8:sts=4:tw=80 33 | -------------------------------------------------------------------------------- /extension/clib/msg.c: -------------------------------------------------------------------------------- 1 | /* 2 | * extension/clib/msg.c - Lua logging interface 3 | * 4 | * Copyright © 2016 Aidan Holm 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #include "extension/clib/msg.h" 22 | #include "common/clib/msg.h" 23 | 24 | void 25 | msg_lib_setup(lua_State *L) 26 | { 27 | static const struct luaL_Reg msg_lib[] = 28 | { 29 | #define X(name) \ 30 | { #name, luaH_msg_##name }, 31 | LOG_LEVELS 32 | #undef X 33 | { NULL, NULL } 34 | }; 35 | 36 | /* export luakit lib */ 37 | luaH_openlib(L, "msg", msg_lib, msg_lib); 38 | 39 | /* Store ref to string.format() */ 40 | lua_getglobal(L, "string"); 41 | lua_getfield(L, -1, "format"); 42 | string_format_ref = luaH_object_ref(L, -1); 43 | lua_pop(L, 1); 44 | 45 | /* Store ref to tostring() */ 46 | lua_getglobal(L, "tostring"); 47 | tostring_ref = luaH_object_ref(L, -1); 48 | } 49 | 50 | // vim: ft=c:et:sw=4:ts=8:sts=4:tw=80 51 | -------------------------------------------------------------------------------- /extension/clib/msg.h: -------------------------------------------------------------------------------- 1 | /* 2 | * extension/clib/msg.h - Lua logging interface 3 | * 4 | * Copyright © 2017 Aidan Holm 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #ifndef LUAKIT_EXTENSION_CLIB_MSG_H 22 | #define LUAKIT_EXTENSION_CLIB_MSG_H 23 | 24 | #include 25 | 26 | void msg_lib_setup(lua_State *L); 27 | 28 | #endif 29 | 30 | // vim: ft=c:et:sw=4:ts=8:sts=4:tw=80 31 | -------------------------------------------------------------------------------- /extension/clib/page.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2016 Aidan Holm 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | * 17 | */ 18 | 19 | #ifndef LUAKIT_EXTENSION_CLIB_PAGE_H 20 | #define LUAKIT_EXTENSION_CLIB_PAGE_H 21 | 22 | #include 23 | 24 | #include "common/util.h" 25 | #include "common/luaclass.h" 26 | #include "common/luaobject.h" 27 | 28 | #include 29 | 30 | typedef struct _page_t { 31 | LUA_OBJECT_HEADER 32 | WebKitWebPage *page; 33 | /* Lua object ref */ 34 | gpointer ref; 35 | } page_t; 36 | 37 | void page_class_setup(lua_State *); 38 | gint luaH_page_from_web_page(lua_State *L, WebKitWebPage *web_page); 39 | 40 | #endif 41 | 42 | // vim: ft=c:et:sw=4:ts=8:sts=4:tw=80 43 | -------------------------------------------------------------------------------- /extension/clib/soup.c: -------------------------------------------------------------------------------- 1 | /* 2 | * extension/clib/soup.c - soup library 3 | * 4 | * Copyright © 2011 Mason Larobina 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #include "luah.h" 22 | #include "clib/soup.h" 23 | #include "common/property.h" 24 | #include "common/signal.h" 25 | #include "web_context.h" 26 | 27 | #include 28 | #include 29 | 30 | static lua_class_t soup_class; 31 | LUA_CLASS_FUNCS(soup, soup_class); 32 | 33 | #include "common/clib/soup.h" 34 | 35 | void 36 | soup_lib_setup(lua_State *L) 37 | { 38 | soup_lib_setup_common(); 39 | 40 | static const struct luaL_Reg soup_lib[] = 41 | { 42 | LUA_CLASS_METHODS(soup) 43 | { "parse_uri", luaH_soup_parse_uri }, 44 | { "uri_tostring", luaH_soup_uri_tostring }, 45 | { NULL, NULL }, 46 | }; 47 | 48 | /* create signals array */ 49 | soup_class.signals = signal_new(); 50 | 51 | /* export soup lib */ 52 | luaH_openlib(L, "soup", soup_lib, soup_lib); 53 | } 54 | 55 | // vim: ft=c:et:sw=4:ts=8:sts=4:tw=80 56 | -------------------------------------------------------------------------------- /extension/clib/soup.h: -------------------------------------------------------------------------------- 1 | /* 2 | * extension/clib/soup.h - soup library 3 | * 4 | * Copyright © 2011 Mason Larobina 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #ifndef LUAKIT_EXTENSION_CLIB_SOUP_H 22 | #define LUAKIT_EXTENSION_CLIB_SOUP_H 23 | 24 | #include 25 | 26 | void soup_lib_setup(lua_State *L); 27 | 28 | #endif 29 | 30 | // vim: ft=c:et:sw=4:ts=8:sts=4:tw=80 31 | -------------------------------------------------------------------------------- /extension/extension.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2016 Aidan Holm 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | * 17 | */ 18 | 19 | #ifndef LUAKIT_EXTENSION_EXTENSION_H 20 | #define LUAKIT_EXTENSION_EXTENSION_H 21 | 22 | #pragma GCC diagnostic push 23 | #pragma GCC diagnostic ignored "-Wunknown-pragmas" 24 | #pragma clang diagnostic push 25 | #pragma clang diagnostic ignored "-Wtypedef-redefinition" 26 | #include 27 | #pragma clang diagnostic pop 28 | #pragma GCC diagnostic pop 29 | 30 | #include 31 | #include 32 | #include "extension/ipc.h" 33 | #include "common/common.h" 34 | 35 | typedef struct _extension_t { 36 | /** Handle to the WebKit Web Extension */ 37 | WebKitWebExtension *ext; 38 | /** Channel for IPC with ui process */ 39 | ipc_endpoint_t *ipc; 40 | /** Isolated JavaScript context */ 41 | WebKitScriptWorld *script_world; 42 | } extension_t; 43 | 44 | extension_t extension; 45 | 46 | #endif 47 | 48 | // vim: ft=c:et:sw=4:ts=8:sts=4:tw=80 49 | -------------------------------------------------------------------------------- /extension/ipc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2016 Aidan Holm 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | * 17 | */ 18 | 19 | #ifndef LUAKIT_EXTENSION_IPC_H 20 | #define LUAKIT_EXTENSION_IPC_H 21 | 22 | #include "common/ipc.h" 23 | 24 | int web_extension_connect(const gchar *socket_path); 25 | void emit_pending_page_creation_ipc(void); 26 | 27 | void ipc_recv_lua_require_module(ipc_endpoint_t *from, const ipc_lua_require_module_t *msg, guint length); 28 | void ipc_recv_lua_ipc(ipc_endpoint_t *from, const ipc_lua_ipc_t *msg, guint length); 29 | 30 | #endif 31 | 32 | // vim: ft=c:et:sw=4:ts=8:sts=4:tw=80 33 | -------------------------------------------------------------------------------- /extension/log.c: -------------------------------------------------------------------------------- 1 | /* 2 | * extension/log.c - logging interface for web extension 3 | * 4 | * Copyright © 2016 Aidan Holm 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #include "extension/extension.h" 22 | #include "common/log.h" 23 | #include "common/ipc.h" 24 | 25 | #include 26 | 27 | void 28 | _log(log_level_t lvl, const gchar *fct, const gchar *fmt, ...) { 29 | va_list ap; 30 | va_start(ap, fmt); 31 | va_log(lvl, fct, fmt, ap); 32 | va_end(ap); 33 | } 34 | 35 | void 36 | va_log(log_level_t lvl, const gchar *fct, const gchar *fmt, va_list ap) { 37 | lua_State *L = common.L; 38 | gchar *msg = g_strdup_vprintf(fmt, ap); 39 | 40 | lua_pushinteger(L, lvl); 41 | lua_pushstring(L, fct); 42 | lua_pushstring(L, msg); 43 | ipc_send_lua(extension.ipc, IPC_TYPE_log, L, -3, -1); 44 | lua_pop(L, 3); 45 | 46 | g_free(msg); 47 | } 48 | 49 | // vim: ft=c:et:sw=4:ts=8:sts=4:tw=80 50 | -------------------------------------------------------------------------------- /extension/luajs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2016 Aidan Holm 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | * 17 | */ 18 | 19 | #ifndef LUAKIT_EXTENSION_LUAJS_H 20 | #define LUAKIT_EXTENSION_LUAJS_H 21 | 22 | #include 23 | 24 | void web_luajs_init(void); 25 | void luaJS_register_function(lua_State *L); 26 | void ipc_recv_lua_js_call(ipc_endpoint_t *from, const guint8 *msg, guint length); 27 | void ipc_recv_lua_js_register(ipc_endpoint_t *from, const guint8 *msg, guint length); 28 | 29 | #endif 30 | 31 | // vim: ft=c:et:sw=4:ts=8:sts=4:tw=80 32 | -------------------------------------------------------------------------------- /extension/script_world.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2016 Aidan Holm 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | * 17 | */ 18 | 19 | #include "extension/extension.h" 20 | 21 | void 22 | web_script_world_init(void) 23 | { 24 | extension.script_world = webkit_script_world_new(); 25 | } 26 | 27 | // vim: ft=c:et:sw=4:ts=8:sts=4:tw=80 28 | -------------------------------------------------------------------------------- /extension/script_world.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2016 Aidan Holm 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | * 17 | */ 18 | 19 | #ifndef LUAKIT_EXTENSION_SCRIPT_WORLD_H 20 | #define LUAKIT_EXTENSION_SCRIPT_WORLD_H 21 | 22 | #include 23 | 24 | void web_script_world_init(void); 25 | 26 | #endif 27 | 28 | // vim: ft=c:et:sw=4:ts=8:sts=4:tw=80 29 | -------------------------------------------------------------------------------- /extension/scroll.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2016 Aidan Holm 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | * 17 | */ 18 | 19 | #ifndef LUAKIT_EXTENSION_SCROLL_H 20 | #define LUAKIT_EXTENSION_SCROLL_H 21 | 22 | #include 23 | 24 | void web_scroll_to(guint64 page_id, gint scroll_x, gint scroll_y); 25 | void web_scroll_init(void); 26 | 27 | #endif 28 | 29 | // vim: ft=c:et:sw=4:ts=8:sts=4:tw=80 30 | -------------------------------------------------------------------------------- /extras/PKGBUILD: -------------------------------------------------------------------------------- 1 | # Maintainer: Robbie Smith 2 | 3 | pkgname=luakit-git 4 | _gitname=luakit 5 | pkgver=20130501.g807dc42 6 | pkgrel=1 7 | pkgdesc="A fast, small, webkit-gtk based browser extensible by Lua" 8 | arch=('i686' 'x86_64') 9 | url="https://luakit.github.io/" 10 | license=('GPL3') 11 | depends=('libwebkit' 'lua-filesystem' 'libunique') 12 | makedepends=('git' 'lua' 'help2man') 13 | optdepends=('luajit2: Needed if use the luajit option in make') 14 | # Luakit crowd fork 15 | source=($_gitname.install 'luakit::git+https://github.com/luakit-crowd/luakit.git#branch=develop') 16 | # Mason Larobina’s master 17 | #source=($_gitname.install 'luakit::git+https://github.com/mason-larobina/luakit.git#branch=develop') 18 | md5sums=('184069a7264115726f73204d1d708e2c' 'SKIP') 19 | provides=(luakit) 20 | conflicts=('luakit' 'luakit-develop-git') 21 | install=$_gitname.install 22 | options=(!strip) 23 | backup=('etc/xdg/luakit/binds.lua' 24 | 'etc/xdg/luakit/globals.lua' 25 | 'etc/xdg/luakit/modes.lua' 26 | 'etc/xdg/luakit/rc.lua' 27 | 'etc/xdg/luakit/theme.lua' 28 | 'etc/xdg/luakit/webview.lua' 29 | 'etc/xdg/luakit/window.lua') 30 | 31 | _gitbranch="develop" 32 | 33 | # To disable lua’s just-in-time compiler, remove USE_LUAJIT=1 from the below line: 34 | _makeopts="PREFIX=/usr DEVELOPMENT_PATHS=0 USE_LUAJIT=1" 35 | 36 | 37 | pkgver() { 38 | cd $_gitname 39 | # Package version is the date of the last commit + the SHA tag 40 | git log -1 --format="%cd.g%h" --date=short | sed 's/-//g' 41 | # Package version is the tag of the last commit 42 | #echo $(git describe --always | sed 's|-|.|g') 43 | } 44 | 45 | build() { 46 | cd $_gitname 47 | make $_makeopts all 48 | } 49 | 50 | package() { 51 | cd $_gitname 52 | make $_makeopts DESTDIR=${pkgdir} install 53 | 54 | # Install extras 55 | install -Dm 0644 "${srcdir}/$_gitname/extras/vim/ftdetect/luakit.vim" "${pkgdir}/usr/share/vim/vimfiles/ftdetect/luakit.vim" 56 | install -Dm 0644 "${srcdir}/$_gitname/extras/vim/ftplugin/luakit.vim" "${pkgdir}/usr/share/vim/vimfiles/ftplugin/luakit.vim" 57 | install -Dm 0644 "${srcdir}/$_gitname/extras/vim/indent/luakit.vim" "${pkgdir}/usr/share/vim/vimfiles/indent/luakit.vim" 58 | install -Dm 0644 "${srcdir}/$_gitname/extras/vim/syntax/luakit.vim" "${pkgdir}/usr/share/vim/vimfiles/syntax/luakit.vim" 59 | } 60 | 61 | # vim:set ts=2 sw=2 et: 62 | -------------------------------------------------------------------------------- /extras/bookmarks_migrate.lua: -------------------------------------------------------------------------------- 1 | local usage = [[Usage: luakit -c bookmark_migrate.lua [old bookmark db path] [new bookmark db path] 2 | 3 | Imports bookmarks from old database schema: 4 | 5 | CREATE TABLE IF NOT EXISTS bookmarks ( 6 | id INTEGER PRIMARY KEY, 7 | uri TEXT NOT NULL, 8 | title TEXT, 9 | desc TEXT, 10 | created INTEGER, 11 | modified INTEGER 12 | ); 13 | 14 | CREATE TABLE IF NOT EXISTS tags ( 15 | id INTEGER PRIMARY KEY, 16 | name TEXT 17 | ); 18 | 19 | CREATE TABLE IF NOT EXISTS tagmap ( 20 | id INTEGER PRIMARY KEY, 21 | bookmark_id INTEGER, 22 | tag_id INTEGER, 23 | FOREIGN KEY(bookmark_id) REFERENCES bookmarks(id), 24 | FOREIGN KEY(tag_id) REFERENCES tags(id) 25 | ); 26 | 27 | To the new schema: 28 | 29 | CREATE TABLE IF NOT EXISTS bookmarks ( 30 | id INTEGER PRIMARY KEY, 31 | uri TEXT NOT NULL, 32 | title TEXT NOT NULL, 33 | desc TEXT NOT NULL, 34 | tags TEXT NOT NULL, 35 | created INTEGER, 36 | modified INTEGER 37 | ); 38 | ]] 39 | 40 | local old_db_path, new_db_path = unpack(uris) 41 | 42 | if not old_db_path or not new_db_path then 43 | io.stdout:write(usage) 44 | luakit.quit(1) 45 | end 46 | 47 | old_db = sqlite3{ filename = old_db_path } 48 | new_db = sqlite3{ filename = new_db_path } 49 | 50 | local rows = old_db:exec [[ 51 | SELECT b.*, group_concat(t.name, ' ') AS tags 52 | FROM bookmarks AS b 53 | LEFT JOIN tagmap AS map LEFT JOIN tags AS t 54 | ON map.bookmark_id = b.id AND map.tag_id = t.id 55 | GROUP BY b.id 56 | ]] 57 | 58 | for i, b in ipairs(rows) do 59 | print(string.format("IMPORT (%q, %q, %q, %q, %d, %d)", 60 | b.uri or "", b.title or "", b.desc or "", b.tags or "", 61 | b.created or 0, b.modified or 0)) 62 | 63 | new_db:exec("INSERT INTO bookmarks VALUES (NULL, ?, ?, ?, ?, ?, ?)", { 64 | b.uri or "", b.title or "", b.desc or "", b.tags or "", 65 | b.created or os.time(), b.modified or os.time() 66 | }) 67 | end 68 | 69 | print("Import finished.") 70 | 71 | print("\nVacuuming database...") 72 | new_db:exec "VACUUM" 73 | print("Vacuum done.") 74 | 75 | luakit.quit(0) 76 | 77 | -- vim: et:sw=4:ts=8:sts=4:tw=80 78 | -------------------------------------------------------------------------------- /extras/luakit.desktop: -------------------------------------------------------------------------------- 1 | [Desktop Entry] 2 | Name=Luakit 3 | Comment=Fast, small, webkit based micro-browser extensible by Lua 4 | Exec=luakit %u 5 | Icon=luakit 6 | Terminal=false 7 | Type=Application 8 | Categories=Network;WebBrowser; 9 | MimeType=text/html;text/xml;application/xhtml+xml;x-scheme-handler/http;x-scheme-handler/https; 10 | -------------------------------------------------------------------------------- /extras/luakit.install: -------------------------------------------------------------------------------- 1 | post_install() { 2 | 3 | echo -e "\n Configs are located in /etc/xdg/luakit/*.lua \n Copy to ~/.config/luakit/ (this folder is created on 1st start of Luakit) for local config. \n Or edit in place for global changes. \n There are now SEVERAL files.. not just the one rc.lua \n \n If you want to link against the Just-In-Time compiler you can build using 'USE_LUAJIT=1 makepkg' Or add 'USE_LUAJIT=1' to the makeopts variable line in PKGBUILD. \n \n See also PKGBUILD comments for use case" 4 | 5 | } 6 | 7 | post_upgrade() { 8 | echo -e "\n Configs are located in /etc/xdg/luakit/*.lua \n Copy to ~/.config/luakit/ (this folder is created on 1st start of Luakit) for local config. \n Or edit in place for global changes. \n There are now SEVERAL files.. not just the one rc.lua \n \n If you want to link against the Just-In-Time compiler you can build using 'USE_LUAJIT=1 makepkg' Or add 'USE_LUAJIT=1' to the makeopts variable line in PKGBUILD. \n \n See also PKGBUILD comments for use case" 9 | 10 | } 11 | 12 | # vim:set ts=2 sw=2 et: 13 | -------------------------------------------------------------------------------- /extras/luakit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aidanholm/luakit/9798a1d9bb0598efeb07403b64a5b535dd34eff1/extras/luakit.png -------------------------------------------------------------------------------- /extras/vim/ftdetect/luakit.vim: -------------------------------------------------------------------------------- 1 | au BufNewFile,BufRead */luakit/**/*.lua set ft=luakit 2 | au BufNewFile,BufRead */luakit/*.lua set ft=luakit 3 | -------------------------------------------------------------------------------- /extras/vim/ftplugin/luakit.vim: -------------------------------------------------------------------------------- 1 | " Vim filetype plugin 2 | " Language: luakit configuration 3 | " Maintainer: Gregor Uhlenheuer 4 | " Last Change: Tue 14 Sep 2010 01:18:20 PM CEST 5 | 6 | " Custom configuration: 7 | " 8 | " Set 'g:luakit_prefix' to the path prefix where the system-wide 9 | " luakit configuration files are installed to. The default is set to 10 | " something like '/etc/xdg' or '/usr/share/xdg'. 11 | " If this variable is not defined the path is tried to determine via the 12 | " environment variable $XDG_CONFIG_DIRS 13 | " 14 | " let g:luakit_prefix = '/etc/xdg' 15 | " 16 | " Defined mappings (buffer-local): 17 | " 18 | " ld Diff current config file with its system-wide counterpart 19 | 20 | if exists('b:did_luakit') 21 | finish 22 | endif 23 | let b:did_luakit = 1 24 | 25 | if !exists('g:luakit_prefix') 26 | let g:luakit_prefix = '/etc/xdg' 27 | endif 28 | 29 | function! s:GetFile() 30 | let fcomponents = [] 31 | if $XDG_CONFIG_DIRS != '' 32 | call add(fcomponents, $XDG_CONFIG_DIRS) 33 | else 34 | call add(fcomponents, g:luakit_prefix) 35 | endif 36 | call add(fcomponents, "luakit") 37 | call add(fcomponents, expand('%:t')) 38 | let config_file = join(fcomponents, '/') 39 | if filereadable(config_file) 40 | return config_file 41 | endif 42 | return '' 43 | endfunction 44 | 45 | if !exists('*CompareLuakitFile') 46 | function! CompareLuakitFile() 47 | let file = GetFile() 48 | if file != '' 49 | if file != expand('%:p') 50 | exe 'vert diffsplit' file 51 | wincmd p 52 | else 53 | echohl WarningMsg 54 | echom 'You cannot compare the file with itself' 55 | echohl None 56 | endif 57 | else 58 | echohl WarningMsg 59 | echom 'Could not find system-wide luakit '''.expand('%:t').''' file' 60 | echom 'Please define ''g:luakit_prefix''' 61 | echohl None 62 | endif 63 | endfunction 64 | endif 65 | 66 | com! -buffer LuakitDiff call CompareLuakitFile() 67 | nmap ld :LuakitDiff 68 | 69 | runtime! ftplugin/lua.vim 70 | -------------------------------------------------------------------------------- /extras/vim/indent/luakit.vim: -------------------------------------------------------------------------------- 1 | " Vim indent file 2 | " Language: luakit configuration 3 | " Maintainer: Gregor Uhlenheuer 4 | " Last Change: Fri 27 Aug 2010 09:49:20 PM CEST 5 | 6 | if exists('b:did_indent') 7 | finish 8 | endif 9 | 10 | runtime! indent/lua.vim 11 | -------------------------------------------------------------------------------- /extras/vim/syntax/luakit.vim: -------------------------------------------------------------------------------- 1 | " Vim syntax file 2 | " Language: luakit configuration 3 | " Maintainer: Gregor Uhlenheuer 4 | " Last Change: Fri 27 Aug 2010 09:46:46 PM CEST 5 | 6 | if exists('b:current_syntax') 7 | finish 8 | endif 9 | 10 | runtime! syntax/lua.vim 11 | 12 | " Javascript between [=[ & ]=] regions 13 | unlet b:current_syntax 14 | syntax include @JAVASCRIPT syntax/javascript.vim 15 | try | syntax include @JAVASCRIPT after/syntax/javascript.vim | catch | endtry 16 | syntax region jsBLOCK matchgroup=jsBLOCKMATCH start=/\[=\[/ end=/\]=\]/ contains=@JAVASCRIPT 17 | hi link jsBLOCKMATCH SpecialComment 18 | 19 | " HTML between [==[ & ]==] regions 20 | unlet b:current_syntax 21 | syntax include @HTML syntax/html.vim 22 | try | syntax include @HTML after/syntax/html.vim | catch | endtry 23 | syntax region htmlBLOCK matchgroup=htmlBLOCKMATCH start=/\[==\[/ end=/\]==\]/ contains=@HTML 24 | hi link htmlBLOCKMATCH SpecialComment 25 | 26 | " CSS between [===[ & ]===] regions 27 | unlet b:current_syntax 28 | syntax include @CSS syntax/css.vim 29 | try | syntax include @CSS after/syntax/css.vim | catch | endtry 30 | syntax region cssBLOCK matchgroup=cssBLOCKMATCH start=/\[===\[/ end=/\]===\]/ contains=@CSS 31 | hi link cssBLOCKMATCH SpecialComment 32 | 33 | let b:current_syntax = 'luakit' 34 | -------------------------------------------------------------------------------- /ipc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2016 Aidan Holm 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | * 17 | */ 18 | 19 | #ifndef LUAKIT_IPC_H 20 | #define LUAKIT_IPC_H 21 | 22 | #include "common/ipc.h" 23 | 24 | void ipc_init(void); 25 | void ipc_endpoint_remove_from_endpoints(ipc_endpoint_t *); 26 | void ipc_remove_socket_file(void); 27 | 28 | #endif 29 | 30 | // vim: ft=c:et:sw=4:ts=8:sts=4:tw=80 31 | -------------------------------------------------------------------------------- /lib/chrome_wm.lua: -------------------------------------------------------------------------------- 1 | -- Add custom luakit:// scheme rendering functions. 2 | -- @submodule chrome 3 | -- @copyright 2017 Aidan Holm 4 | 5 | local ui = ipc_channel("chrome_wm") 6 | 7 | local _M = {} 8 | 9 | local pending = {} 10 | local next_id = 0 11 | 12 | ui:add_signal("function-return", function (_, _, id, ok, ret) 13 | local callbacks = assert(pending[id]) 14 | pending[id] = nil 15 | (callbacks[ok and "resolve" or "reject"])(ret) 16 | end) 17 | 18 | ui:add_signal("register-function", function (_, _, page_name, func_name) 19 | local pattern = "^luakit://" .. page_name .. "/?(.*)" 20 | luakit.register_function(pattern, func_name, function (page, resolve, reject, ...) 21 | pending[next_id] = { resolve = resolve, reject = reject } 22 | ui:emit_signal("function-call", page.id, page_name, func_name, next_id, {...}) 23 | next_id = next_id + 1 24 | end) 25 | end) 26 | 27 | return _M 28 | 29 | -- vim: et:sw=4:ts=8:sts=4:tw=80 30 | -------------------------------------------------------------------------------- /lib/editor.lua: -------------------------------------------------------------------------------- 1 | --- Text editor launching functionality. 2 | -- 3 | -- This module is primarily for use by other Lua modules that wish to 4 | -- allow the user to edit a particular text file. The default is to guess at the 5 | -- shell command to open a text editor from environment variables. To override 6 | -- the guess, replace `editor.cmd_string`. This can be done manually, as follows: 7 | -- 8 | -- local editor = require "editor" 9 | -- editor.editor_cmd = "urxvt -e nvim {file} +{line}" 10 | -- 11 | -- Before running the command, `{file}` will be replaced by the name of the file 12 | -- to be edited, and `{line}` will be replaced by the number of the line at 13 | -- which to begin editing. This module also supplies several builtin command 14 | -- strings, which can be used like this: 15 | -- 16 | -- local editor = require "editor" 17 | -- editor.editor_cmd = editor.builtin.urxvt 18 | -- 19 | -- @module editor 20 | -- @copyright 2017 Graham Leach-Krouse 21 | -- @copyright 2017 Aidan Holm 22 | 23 | local _M = {} 24 | 25 | -- substitute in common values from the environment. 26 | local env_sub = function (s) 27 | local subs = { 28 | term = os.getenv("TERMINAL") or "xterm", 29 | editor = os.getenv("EDITOR") or "vim" 30 | } 31 | return string.gsub(s,"{(%w+)}", subs) 32 | end 33 | 34 | --- Built in substitution strings. Includes 35 | -- 36 | -- * `default` (attempts to extract a terminal and editor from environment 37 | -- variables, and otherwise falls back to xterm and vim) 38 | -- * `xterm` 39 | -- * `urxvt` 40 | -- * `xdg_open` 41 | -- 42 | -- @type table 43 | -- @readonly 44 | _M.builtin = { 45 | default = env_sub("{term} -e '{editor} {file} +{line}'"), 46 | xterm = env_sub("xterm -e {editor} {file} +{line}"), 47 | urxvt = env_sub("urxvt -e {editor} {file} +{line}"), 48 | xdg_open = env_sub("xdg-open {file}") 49 | } 50 | 51 | --- The shell command used to open the editor. 52 | -- 53 | -- @type string 54 | -- @readwrite 55 | _M.editor_cmd = _M.builtin.default 56 | 57 | --- Edit a file in a terminal editor in a new window. 58 | -- 59 | -- * Can't yet handle files with special characters in their name. 60 | -- 61 | -- @tparam string file The path of the file to edit. 62 | -- @tparam[opt] number line The line number at which to begin editing. 63 | -- @tparam[opt] function callback A callback that fires when the process spawned 64 | -- by the editor command exits, of type @ref{process_exit_cb}. 65 | _M.edit = function (file, line, callback) 66 | local subs = { 67 | file = file, 68 | line = line or 1, 69 | } 70 | local cmd = string.gsub(_M.editor_cmd, "{(%w+)}", subs) 71 | luakit.spawn(cmd, callback) 72 | end 73 | 74 | return _M 75 | 76 | -- vim: et:sw=4:ts=8:sts=4:tw=80 77 | -------------------------------------------------------------------------------- /lib/error_page_wm.lua: -------------------------------------------------------------------------------- 1 | -- Error pages - web module. 2 | -- 3 | -- @submodule error_page 4 | -- @copyright 2016 Aidan Holm 5 | 6 | local ui = ipc_channel("error_page_wm") 7 | 8 | ui:add_signal("listen", function(_, page) 9 | local doc = page.document 10 | for i, elem in ipairs(doc.body:query("input[type=button]")) do 11 | elem:add_event_listener("click", true, function (_) 12 | ui:emit_signal("click", page.id, i) 13 | end) 14 | end 15 | end) 16 | 17 | -- vim: et:sw=4:ts=8:sts=4:tw=80 18 | -------------------------------------------------------------------------------- /lib/follow_selected.lua: -------------------------------------------------------------------------------- 1 | --- Add {A,C,S,}-Return binds to follow selected link (or link in selection). 2 | -- 3 | -- This module allows you to follow links that are part of the currently 4 | -- selected text. This is useful as an alternative to the follow mode: search 5 | -- for the text of the link, and then press `` to follow it. 6 | -- 7 | -- @module follow_selected 8 | -- @copyright 2010 Chris van Dijk 9 | -- @copyright 2010 Mason Larobina 10 | -- @copyright 2010 Paweł Zuzelski 11 | -- @copyright 2009 israellevin 12 | 13 | local window = require("window") 14 | local modes = require("modes") 15 | local add_binds = modes.add_binds 16 | 17 | local _M = {} 18 | 19 | local wm = require_web_module("follow_selected_wm") 20 | 21 | local function get_w_by_view_id(view_id) 22 | for _, w in pairs(window.bywidget) do 23 | if w.view.id == view_id then 24 | return w 25 | end 26 | end 27 | end 28 | 29 | wm:add_signal("navigate", function(_, uri, view_id) 30 | get_w_by_view_id(view_id):navigate(uri) 31 | end) 32 | wm:add_signal("new_tab", function(_, uri, view_id) 33 | get_w_by_view_id(view_id):new_tab(uri) 34 | end) 35 | wm:add_signal("new_window", function(_, uri) 36 | window.new({uri}) 37 | end) 38 | wm:add_signal("download", function(_, uri, view_id) 39 | get_w_by_view_id(view_id):download(uri) 40 | end) 41 | 42 | -- Add binding to normal mode to follow selected link 43 | add_binds("normal", { 44 | { "", "Follow the selected link in the current tab.", 45 | function (w) wm:emit_signal(w.view, "follow_selected", "navigate", w.view.id) end }, 46 | { "", "Follow the selected link in a new tab.", 47 | function (w) wm:emit_signal(w.view, "follow_selected", "new_tab", w.view.id) end }, 48 | { "", "Follow the selected link in a new window.", 49 | function (w) wm:emit_signal(w.view, "follow_selected", "new_window", w.view.id) end }, 50 | { "", "Download the selected link.", 51 | function (w) wm:emit_signal(w.view, "follow_selected", "download", w.view.id) end }, 52 | }) 53 | 54 | return _M 55 | 56 | -- vim: et:sw=4:ts=8:sts=4:tw=80 57 | -------------------------------------------------------------------------------- /lib/follow_selected_wm.lua: -------------------------------------------------------------------------------- 1 | -- Add {A,C,S,}-Return binds to follow selected link (or link in selection) - web module. 2 | -- 3 | -- @submodule follow_selected_wm 4 | -- @copyright 2016 Aidan Holm 5 | -- @copyright 2010 Chris van Dijk 6 | -- @copyright 2010 Mason Larobina 7 | -- @copyright 2010 Paweł Zuzelski 8 | -- @copyright 2009 israellevin 9 | 10 | local ui = ipc_channel("follow_selected_wm") 11 | 12 | -- Return selected uri or first uri in selection 13 | local return_selected = [=[ 14 | (function(document) { 15 | var selection = window.getSelection(), 16 | container = document.createElement('div'), 17 | range, elements, i = 0; 18 | 19 | if (selection.toString() !== "") { 20 | range = selection.getRangeAt(0); 21 | // Check for links contained within the selection 22 | container.appendChild(range.cloneContents()); 23 | 24 | var elements = container.getElementsByTagName('a'), 25 | len = elements.length, i = 0, href; 26 | 27 | for (; i < len;) 28 | if ((href = elements[i++].href)) 29 | return href; 30 | 31 | // Check for links which contain the selection 32 | container = range.startContainer; 33 | while (container !== document) { 34 | if ((href = container.href)) 35 | return href; 36 | container = container.parentNode; 37 | } 38 | } 39 | // Check for active links 40 | var element = document.activeElement; 41 | return element.src || element.href; 42 | })(document); 43 | ]=] 44 | 45 | ui:add_signal("follow_selected", function(_, _, action, view_id) 46 | local p = page(view_id) 47 | local uri = p:eval_js(return_selected) 48 | if not uri then return end 49 | assert(type(uri) == "string") 50 | ui:emit_signal(action, uri, view_id) 51 | end) 52 | 53 | -- vim: et:sw=4:ts=8:sts=4:tw=80 54 | -------------------------------------------------------------------------------- /lib/go_input.lua: -------------------------------------------------------------------------------- 1 | --- Go to the first input on a page and enter insert mode. 2 | -- 3 | -- This module adds a key binding to quickly focus the first text input on a 4 | -- page and enter insert mode. A count is also accepted, which allows choosing a 5 | -- specific text input other than the first. 6 | -- 7 | -- @module go_input 8 | -- @copyright 2009 Aldrik Dunbar 9 | -- @copyright 2010 Paweł Zuzelski 10 | 11 | local webview = require("webview") 12 | local modes = require("modes") 13 | local add_binds = modes.add_binds 14 | 15 | local _M = {} 16 | 17 | local go_input = [=[ 18 | (function (count) { 19 | var elements = document.querySelectorAll("textarea, input" + [ 20 | ":not([type='button'])", ":not([type='checkbox'])", 21 | ":not([type='hidden'])", ":not([type='image'])", 22 | ":not([type='radio'])", ":not([type='reset'])", 23 | ":not([type='submit'])", ":not([type='file'])"].join("")); 24 | if (elements) { 25 | var el, i = 0, n = 0; 26 | while((el = elements[i++])) { 27 | var style = getComputedStyle(el, null); 28 | if (style.display !== 'none' && style.visibility === 'visible') { 29 | n++; 30 | if (n == count) { 31 | if (el.type === "file") { 32 | el.click(); 33 | } else { 34 | el.focus(); 35 | } 36 | return "form-active"; 37 | } 38 | } 39 | } 40 | } 41 | return "root-active"; 42 | })]=] 43 | 44 | -- Add `w:go_input()` webview method 45 | webview.methods.go_input = function(_, w, count) 46 | local js = string.format("%s(%d);", go_input, count or 1) 47 | w.view:eval_js(js, { callback = function(ret) 48 | w:emit_form_root_active_signal(ret) 49 | end}) 50 | end 51 | 52 | -- Add `gi` binding to normal mode 53 | add_binds("normal", { 54 | { "gi", "Focus the first text input on the current page and enter insert mode.", 55 | function (w, _, m) w:go_input(m.count) end, {count=1} } 56 | }) 57 | 58 | return _M 59 | 60 | -- vim: et:sw=4:ts=8:sts=4:tw=80 61 | -------------------------------------------------------------------------------- /lib/hide_scrollbars.lua: -------------------------------------------------------------------------------- 1 | --- Hide scrollbars. 2 | -- 3 | -- Hides all element scrollbars. Elements can still be scrolled as usual. 4 | -- 5 | -- @module hide_scrollbars 6 | -- @copyright 2016 Aidan Holm 7 | 8 | local webview = require("webview") 9 | 10 | local _M = {} 11 | 12 | local disable_scrollbar_ss = stylesheet{ source = [===[ 13 | ::-webkit-scrollbar { 14 | width: 0 !important; 15 | height: 0 !important; 16 | } 17 | ]===] } 18 | 19 | webview.add_signal("init", function (view) 20 | view.stylesheets[disable_scrollbar_ss] = true 21 | end) 22 | 23 | return _M 24 | 25 | -- vim: et:sw=4:ts=8:sts=4:tw=80 26 | -------------------------------------------------------------------------------- /lib/image_css_wm.lua: -------------------------------------------------------------------------------- 1 | -- Customize how single images are displayed in the browser. 2 | -- 3 | -- @submodule image_css 4 | -- @copyright 2017 Aidan Holm 5 | 6 | local ui = ipc_channel("image_css_wm") 7 | 8 | local recalc_funcs = setmetatable({}, { __mode = "k" }) 9 | 10 | ui:add_signal("image", function (_, page) 11 | local body = page.document.body 12 | 13 | -- do nothing if loaded document is not HTML 14 | if not body then return end 15 | 16 | local img = body:query("img")[1] 17 | if not img then return end 18 | 19 | recalc_funcs[page] = function () 20 | local body_height = body.rect.height 21 | local img_height = img.rect.height 22 | local vert_overflow = img_height > body_height 23 | img.attr.class = vert_overflow and "verticalOverflow" or "" 24 | end 25 | 26 | img:add_signal("destroy", function () 27 | recalc_funcs[page] = nil 28 | end) 29 | 30 | img:add_event_listener("click", true, recalc_funcs[page]) 31 | end) 32 | 33 | ui:add_signal("recalc", function (_, page) 34 | return recalc_funcs[page] and recalc_funcs[page](); 35 | end) 36 | 37 | -- vim: et:sw=4:ts=8:sts=4:tw=80 38 | -------------------------------------------------------------------------------- /lib/lousy/init.lua: -------------------------------------------------------------------------------- 1 | --- lousy library. 2 | -- 3 | -- @module lousy 4 | -- @author Mason Larobina 5 | -- @copyright 2010 Mason Larobina 6 | 7 | return { 8 | util = require("lousy.util"), 9 | bind = require("lousy.bind"), 10 | mode = require("lousy.mode"), 11 | theme = require("lousy.theme"), 12 | signal = require("lousy.signal"), 13 | widget = require("lousy.widget"), 14 | uri = require("lousy.uri"), 15 | load = require("lousy.load"), 16 | pickle = require("lousy.pickle"), 17 | } 18 | 19 | -- vim: et:sw=4:ts=8:sts=4:tw=80 20 | -------------------------------------------------------------------------------- /lib/lousy/load.lua: -------------------------------------------------------------------------------- 1 | --- lousy.load library. 2 | -- 3 | -- This module provides a function to search for and load the contents of 4 | -- files. 5 | -- 6 | -- @module lousy.load 7 | -- @author Mason Larobina 8 | -- @copyright 2010 Mason Larobina 9 | 10 | local _M = {} 11 | 12 | -- Keep loaded resources in memory 13 | local data = {} 14 | 15 | local function load_resource(path, memorize) 16 | -- Have we already loaded this resource? 17 | if memorize and data[path] then 18 | return data[path] 19 | end 20 | -- Attempt to open & read resource 21 | local file = io.open(path) 22 | if file then 23 | -- Read resource 24 | local dat = file:read("*a") 25 | file:close() 26 | -- Memorize if asked 27 | if memorize then data[path] = dat end 28 | -- Return file contents 29 | return dat 30 | end 31 | end 32 | 33 | --- @function __call 34 | -- Load the contents of a file, with optional caching. 35 | -- @tparam string path The path of the file to load. If the path is a relative 36 | -- path, it is relative to the luakit installation path. 37 | -- @tparam boolean memorize Whether file loads should be cached. If not `true`, 38 | -- the cache will not be queried for an already-loaded copy, nor will the cache 39 | -- be populated on a successful load. 40 | 41 | local function search_load(path, memorize) 42 | assert(type(path) == "string", "invalid path") 43 | memorize = not not memorize 44 | 45 | if string.sub(path, 1, 1) ~= "/" then 46 | -- Can we search relative paths? 47 | if luakit.dev_paths then 48 | local dat = load_resource("./"..path, memorize) 49 | if dat then return dat end 50 | end 51 | path = luakit.install_paths.install_dir.."/"..path 52 | end 53 | 54 | return assert(load_resource(path, memorize), 55 | "unable to load resource: " .. path) 56 | end 57 | 58 | return setmetatable(_M, { __call = function (_, ...) return search_load(...) end }) 59 | 60 | -- vim: et:sw=4:ts=8:sts=4:tw=80 61 | -------------------------------------------------------------------------------- /lib/lousy/mode.lua: -------------------------------------------------------------------------------- 1 | --- lousy.mode library. 2 | -- 3 | -- Mode setting and getting operations for objects. 4 | -- 5 | -- @module lousy.mode 6 | -- @author Mason Larobina 7 | -- @copyright 2010 Mason Larobina 8 | 9 | local _M = {} 10 | 11 | --- The default mode if no default modes are set. 12 | local default_mode = "normal" 13 | 14 | --- Weak table of objects current modes. 15 | local current_modes = {} 16 | setmetatable(current_modes, { __mode = "k" }) 17 | 18 | --- Weak table of objects default modes. 19 | local default_modes = {} 20 | setmetatable(default_modes, { __mode = "k" }) 21 | 22 | --- Check if the mode can be set on an object. 23 | -- An object is considered mode-able if it has an "emit_signal" method. 24 | -- @param object The object to check. 25 | function _M.is_modeable(object) 26 | local t = type(object) 27 | return ((t == "table" or t == "userdata" or t == "lightuserdata") 28 | and type(object.emit_signal) == "function") 29 | end 30 | 31 | --- Get the current mode for a given object. 32 | -- @param object A mode-able object. 33 | -- @treturn string The current mode of the given object, or the default mode of that object, 34 | -- or "normal". 35 | function _M.get(object) 36 | if not _M.is_modeable(object) then 37 | return error("attempt to get mode on non-modeable object") 38 | end 39 | return current_modes[object] or default_modes[object] or default_mode 40 | end 41 | 42 | --- Set the mode for a given object. 43 | -- @param object A mode-able object. 44 | -- @tparam string mode A mode name (e.g. "insert", "command", ...). 45 | -- @treturn string The newly set mode. 46 | function _M.set(object, mode, ...) 47 | if not _M.is_modeable(object) then 48 | return error("attempt to set mode on non-modeable object") 49 | end 50 | mode = mode or default_modes[object] or default_mode 51 | local changed = current_modes[object] ~= mode 52 | current_modes[object] = mode 53 | -- Raises a mode change signal on the object. 54 | if changed then 55 | object:emit_signal("mode-changed", mode, ...) 56 | end 57 | return mode 58 | end 59 | 60 | return setmetatable(_M, { __call = function(_, ...) return _M.set(...) end }) 61 | 62 | -- vim: et:sw=4:ts=8:sts=4:tw=80 63 | -------------------------------------------------------------------------------- /lib/lousy/theme.lua: -------------------------------------------------------------------------------- 1 | --- lousy.theme library. 2 | -- 3 | -- This module provides theme variable lookup for other modules. 4 | -- 5 | -- @module lousy.theme 6 | -- @author Mason Larobina 7 | -- @author Damien Leone 8 | -- @author Julien Danjou 9 | -- @copyright 2008-2009 Damien Leone 10 | -- @copyright 2008-2009 Julien Danjou 11 | -- @copyright 2010 Mason Larobina 12 | 13 | local util = require "lousy.util" 14 | 15 | local theme 16 | 17 | local _M = {} 18 | 19 | -- Searches recursively for theme value. 20 | -- (I.e. `w.bg = theme.some_thing_bg` -> 21 | -- `w.bg = (theme.some_thing_bg or theme.thing_bg or theme.bg)`) 22 | local function index(t, k) 23 | local v = rawget(t, k) 24 | if v then return v end 25 | -- Knock a "level_" from the key name 26 | if string.find(k, "_") then 27 | local ret = index(t, string.sub(k, string.find(k, "_") + 1, -1)) 28 | -- Cache result 29 | if ret then t[k] = ret end 30 | return ret 31 | end 32 | end 33 | 34 | -- Minimum default theme 35 | local default_theme = { 36 | fg = "#fff", 37 | bg = "#000", 38 | font = "9px monospace", 39 | } 40 | 41 | --- Load the theme table from file. 42 | -- @tparam string path The filepath of the theme. 43 | function _M.init(path) 44 | if not path then return error("error loading theme: no path specified") end 45 | -- Load theme table 46 | local success 47 | success, theme = pcall(function() return dofile(path) end) 48 | if not success then 49 | return error("error loading theme file " .. theme) 50 | elseif not theme then 51 | return error("error loading theme file " .. path) 52 | elseif type(theme) ~= "table" then 53 | return error("error loading theme: not a table") 54 | end 55 | -- Merge with defaults and set metatable 56 | theme = setmetatable(util.table.join(default_theme, theme), { __index = index }) 57 | return theme 58 | end 59 | 60 | --- Get the current theme. 61 | -- @treturn table The current theme table. 62 | function _M.get() 63 | return theme 64 | end 65 | 66 | return _M 67 | 68 | -- vim: et:sw=4:ts=8:sts=4:tw=80 69 | -------------------------------------------------------------------------------- /lib/lousy/widget/buf.lua: -------------------------------------------------------------------------------- 1 | --- Input buffer - status bar widget. 2 | -- 3 | -- Shows the current contents of the input buffer in the status bar. 4 | -- 5 | -- @module lousy.widget.buf 6 | -- @copyright 2017 Aidan Holm 7 | -- @copyright 2010 Mason Larobina 8 | 9 | local window = require("window") 10 | local lousy = require("lousy") 11 | local theme = lousy.theme.get() 12 | local wc = require("lousy.widget.common") 13 | 14 | local _M = {} 15 | 16 | local widgets = { 17 | update = function (w, buf) 18 | if w.buffer then 19 | buf.text = lousy.util.escape(string.format(" %-3s", w.buffer)) 20 | buf:show() 21 | else 22 | buf:hide() 23 | end 24 | end, 25 | } 26 | 27 | local function new() 28 | local buf = widget{type="label"} 29 | buf:hide() 30 | buf.fg = theme.buf_sbar_fg 31 | buf.font = theme.buf_sbar_font 32 | return wc.add_widget(widgets, buf) 33 | end 34 | 35 | window.methods.update_buf = function (w) wc.update_widgets_on_w(widgets, w) end 36 | 37 | return setmetatable(_M, { __call = function(_, ...) return new(...) end }) 38 | 39 | -- vim: et:sw=4:ts=8:sts=4:tw=80 40 | -------------------------------------------------------------------------------- /lib/lousy/widget/common.lua: -------------------------------------------------------------------------------- 1 | --- Common functions for implementing widgets. 2 | -- 3 | -- @module lousy.widget.common 4 | -- @copyright 2017 Aidan Holm 5 | 6 | local window = require("window") 7 | local lousy = require("lousy") 8 | 9 | local _M = {} 10 | 11 | --- Add `widget` to `widgets`, and automatically remove it when `widget` is 12 | -- destroyed. 13 | -- @tparam table widgets A table of widgets 14 | -- @tparam widget widget A newly-created widget 15 | -- @return Returns `widget`, to allow easy chaining. 16 | _M.add_widget = function (widgets, widget) 17 | assert(type(widgets) == "table") 18 | table.insert(widgets, widget) 19 | widget:add_signal("destroy", function (wi) 20 | table.remove(widgets, lousy.util.table.hasitem(widgets, wi)) 21 | end) 22 | return widget 23 | end 24 | 25 | --- Update all widgets in `widgets` on the given window. 26 | -- @tparam table widgets A table of widgets 27 | -- @tparam table w A window table 28 | _M.update_widgets_on_w = function (widgets, w, ...) 29 | assert(type(widgets) == "table") 30 | assert(w.win.type == "window") 31 | for _, widget in ipairs(widgets) do 32 | if window.ancestor(widget) == w then 33 | widgets.update(w, widget, ...) 34 | end 35 | end 36 | end 37 | 38 | return _M 39 | 40 | -- vim: et:sw=4:ts=8:sts=4:tw=80 41 | -------------------------------------------------------------------------------- /lib/lousy/widget/hist.lua: -------------------------------------------------------------------------------- 1 | --- Web page history - status bar widget. 2 | -- 3 | -- Indicates whether the current page can go back or go forward. 4 | -- 5 | -- The widget will not be shown if the current page cannot go back or forward. 6 | -- 7 | -- @module lousy.widget.hist 8 | -- @copyright 2017 Aidan Holm 9 | -- @copyright 2010 Mason Larobina 10 | 11 | local webview = require("webview") 12 | local lousy = require("lousy") 13 | local theme = lousy.theme.get() 14 | local wc = require("lousy.widget.common") 15 | 16 | local _M = {} 17 | 18 | --- Format string which defines the appearance of the widget. 19 | -- The text `{back}` is replaced with the back indicator, and the text 20 | -- `{forward}` is replaced with the forward indicator. 21 | -- @type string 22 | -- @readwrite 23 | _M.format = "[{back}{forward}]" 24 | 25 | --- Text used to indicate that the current page can go back. 26 | -- @type string 27 | -- @readwrite 28 | _M.back_indicator = "+" 29 | 30 | --- Text used to indicate that the current page can go forward. 31 | -- @type string 32 | -- @readwrite 33 | _M.forward_indicator = "-" 34 | 35 | local widgets = { 36 | update = function (w, hist) 37 | local back, forward = w.view:can_go_back(), w.view:can_go_forward() 38 | if back or forward then 39 | hist.text = string.gsub(_M.format, "{(%w+)}", { 40 | back = back and _M.back_indicator or "", 41 | forward = forward and _M.forward_indicator or "", 42 | }) 43 | hist:show() 44 | else 45 | hist:hide() 46 | end 47 | end, 48 | } 49 | 50 | webview.add_signal("init", function (view) 51 | -- Update widget when current page changes status 52 | view:add_signal("load-status", function (v) 53 | local w = webview.window(v) 54 | if w and w.view == v then 55 | wc.update_widgets_on_w(widgets, w) 56 | end 57 | end) 58 | view:add_signal("switched-page", function (v) 59 | wc.update_widgets_on_w(widgets, webview.window(v)) 60 | end) 61 | end) 62 | 63 | local function new() 64 | local hist = widget{type="label"} 65 | hist:hide() 66 | hist.fg = theme.hist_sbar_fg 67 | hist.font = theme.hist_sbar_font 68 | return wc.add_widget(widgets, hist) 69 | end 70 | 71 | return setmetatable(_M, { __call = function(_, ...) return new(...) end }) 72 | 73 | -- vim: et:sw=4:ts=8:sts=4:tw=80 74 | -------------------------------------------------------------------------------- /lib/lousy/widget/init.lua: -------------------------------------------------------------------------------- 1 | --- lousy.widget library. 2 | -- 3 | -- @module lousy.widget 4 | -- @author Mason Larobina 5 | -- @copyright 2010 Mason Larobina 6 | 7 | local wrap = function (modname) 8 | return function () return require(modname) end 9 | end 10 | 11 | local wrapped = { 12 | buf = wrap("lousy.widget.buf"), 13 | hist = wrap("lousy.widget.hist"), 14 | menu = wrap("lousy.widget.menu"), 15 | progress = wrap("lousy.widget.progress"), 16 | scroll = wrap("lousy.widget.scroll"), 17 | ssl = wrap("lousy.widget.ssl"), 18 | tabi = wrap("lousy.widget.tabi"), 19 | tablist = wrap("lousy.widget.tablist"), 20 | tab = wrap("lousy.widget.tab"), 21 | uri = wrap("lousy.widget.uri"), 22 | zoom = wrap("lousy.widget.zoom"), 23 | } 24 | 25 | local unwrap = function (t, k) 26 | if wrapped[k] then 27 | t[k] = (wrapped[k])() 28 | wrapped[k] = nil 29 | return t[k] 30 | end 31 | end 32 | 33 | return setmetatable({}, { __index = unwrap }) 34 | 35 | -- vim: et:sw=4:ts=8:sts=4:tw=80 36 | -------------------------------------------------------------------------------- /lib/lousy/widget/progress.lua: -------------------------------------------------------------------------------- 1 | --- Web page load progress - status bar widget. 2 | -- 3 | -- Shows the load progress of the current web page as a percentage. 4 | -- 5 | -- @module lousy.widget.progress 6 | -- @copyright 2017 Aidan Holm 7 | -- @copyright 2010 Mason Larobina 8 | 9 | local webview = require("webview") 10 | local lousy = require("lousy") 11 | local theme = lousy.theme.get() 12 | local wc = require("lousy.widget.common") 13 | 14 | local _M = {} 15 | 16 | local widgets = { 17 | update = function (w, progress) 18 | local p = w.view.progress 19 | if not w.view.is_loading or p == 1 then 20 | progress:hide() 21 | else 22 | progress:show() 23 | progress.text = string.format("(%d%%)", p * 100) 24 | end 25 | end, 26 | } 27 | 28 | webview.add_signal("init", function (view) 29 | -- Update widget when current page changes status 30 | for _, sig in ipairs({"load-status", "property::progress"}) do 31 | view:add_signal(sig, function (v) 32 | local w = webview.window(v) 33 | if w and w.view == v then 34 | wc.update_widgets_on_w(widgets, w) 35 | end 36 | end) 37 | end 38 | view:add_signal("switched-page", function (v) 39 | wc.update_widgets_on_w(widgets, webview.window(v)) 40 | end) 41 | end) 42 | 43 | local function new() 44 | local progress = widget{type="label"} 45 | progress:hide() 46 | progress.fg = theme.sbar_loaded_fg 47 | progress.font = theme.sbar_loaded_font 48 | return wc.add_widget(widgets, progress) 49 | end 50 | 51 | return setmetatable(_M, { __call = function(_, ...) return new(...) end }) 52 | 53 | -- vim: et:sw=4:ts=8:sts=4:tw=80 54 | -------------------------------------------------------------------------------- /lib/lousy/widget/scroll.lua: -------------------------------------------------------------------------------- 1 | --- Web page scroll position - status bar widget. 2 | -- 3 | -- Shows the current scroll position of the web page as a percentage. 4 | -- 5 | -- @module lousy.widget.scroll 6 | -- @copyright 2017 Aidan Holm 7 | -- @copyright 2010 Mason Larobina 8 | 9 | local webview = require("webview") 10 | local lousy = require("lousy") 11 | local theme = lousy.theme.get() 12 | local wc = require("lousy.widget.common") 13 | 14 | local _M = {} 15 | 16 | local widgets = { 17 | update = function (w, label) 18 | w.view:eval_js([=[ 19 | (function () { 20 | var y = window.scrollY; 21 | var max = Math.max(window.document.documentElement.scrollHeight - window.innerHeight, 0); 22 | return y + " " + max; 23 | })() 24 | ]=], { callback = function (scroll, err) 25 | assert(not err, err) 26 | local y, max = scroll:match("^(%S+) (%S+)$") 27 | y, max = tonumber(y), tonumber(max) 28 | local text 29 | if max == 0 then text = "All" 30 | elseif y == 0 then text = "Top" 31 | elseif y == max then text = "Bot" 32 | else text = string.format("%2d%%", (y / max) * 100) 33 | end 34 | if label.text ~= text then label.text = text end 35 | end }) 36 | end, 37 | } 38 | 39 | webview.add_signal("init", function (view) 40 | view:add_signal("expose", function (v) 41 | local w = webview.window(v) 42 | if w.view == v then 43 | wc.update_widgets_on_w(widgets, w) 44 | end 45 | end) 46 | view:add_signal("switched-page", function (v) 47 | wc.update_widgets_on_w(widgets, webview.window(v)) 48 | end) 49 | end) 50 | 51 | local function new() 52 | local scroll = widget{type="label"} 53 | scroll.fg = theme.scroll_sbar_fg 54 | scroll.font = theme.scroll_sbar_font 55 | return wc.add_widget(widgets, scroll) 56 | end 57 | 58 | return setmetatable(_M, { __call = function(_, ...) return new(...) end }) 59 | 60 | -- vim: et:sw=4:ts=8:sts=4:tw=80 61 | -------------------------------------------------------------------------------- /lib/lousy/widget/ssl.lua: -------------------------------------------------------------------------------- 1 | --- Web page security - ssl status bar widget. 2 | -- 3 | -- Indicates whether the connection used to load the current web page 4 | -- was secure. 5 | -- 6 | -- @module lousy.widget.ssl 7 | -- @copyright 2017 Aidan Holm 8 | -- @copyright 2010 Mason Larobina 9 | 10 | local webview = require("webview") 11 | local lousy = require("lousy") 12 | local theme = lousy.theme.get() 13 | local wc = require("lousy.widget.common") 14 | 15 | local _M = {} 16 | 17 | local widgets = { 18 | update = function (w, ssl) 19 | local trusted = w.view:ssl_trusted() 20 | if trusted == true then 21 | ssl.fg = theme.trust_fg 22 | ssl.text = "(trust)" 23 | ssl:show() 24 | elseif string.sub(w.view.uri or "", 1, 4) == "http" then 25 | -- Display (notrust) on http/https URLs 26 | ssl.fg = theme.notrust_fg 27 | ssl.text = "(notrust)" 28 | ssl:show() 29 | else 30 | ssl:hide() 31 | end 32 | end, 33 | } 34 | 35 | webview.add_signal("init", function (view) 36 | -- Update widget when current page changes status 37 | view:add_signal("load-status", function (v, status) 38 | local w = webview.window(v) 39 | if status == "committed" and w and w.view == v then 40 | wc.update_widgets_on_w(widgets, w) 41 | end 42 | end) 43 | view:add_signal("switched-page", function (v) 44 | wc.update_widgets_on_w(widgets, webview.window(v)) 45 | end) 46 | end) 47 | 48 | local function new() 49 | local ssl = widget{type="label"} 50 | ssl:hide() 51 | ssl.fg = theme.ssl_sbar_fg 52 | ssl.font = theme.ssl_sbar_font 53 | return wc.add_widget(widgets, ssl) 54 | end 55 | 56 | return setmetatable(_M, { __call = function(_, ...) return new(...) end }) 57 | 58 | -- vim: et:sw=4:ts=8:sts=4:tw=80 59 | -------------------------------------------------------------------------------- /lib/lousy/widget/tabi.lua: -------------------------------------------------------------------------------- 1 | --- Tab position - status bar widget. 2 | -- 3 | -- Shows the number of the current tab, as well as the total number of 4 | -- tabs in the window. 5 | -- 6 | -- @module lousy.widget.tabi 7 | -- @copyright 2017 Aidan Holm 8 | -- @copyright 2010 Mason Larobina 9 | 10 | local window = require("window") 11 | local webview = require("webview") 12 | local lousy = require("lousy") 13 | local theme = lousy.theme.get() 14 | local wc = require("lousy.widget.common") 15 | 16 | local _M = {} 17 | 18 | local widgets = { 19 | update = function (w, tabi) 20 | tabi.text = string.format("[%d/%d]", w.tabs:current(), w.tabs:count()) 21 | end, 22 | } 23 | 24 | webview.add_signal("init", function (view) 25 | -- Update widget when current page changes status 26 | view:add_signal("switched-page", function (v) 27 | local w = webview.window(v) 28 | wc.update_widgets_on_w(widgets, w) 29 | end) 30 | end) 31 | 32 | window.add_signal("init", function (w) 33 | w.tabs:add_signal("page-added", function () 34 | luakit.idle_add(function () 35 | wc.update_widgets_on_w(widgets, w) 36 | end) 37 | end) 38 | w.tabs:add_signal("page-reordered", function () 39 | wc.update_widgets_on_w(widgets, w) 40 | end) 41 | end) 42 | 43 | local function new() 44 | local tabi = widget{type="label"} 45 | tabi.fg = theme.tabi_sbar_fg 46 | tabi.font = theme.tabi_sbar_font 47 | return wc.add_widget(widgets, tabi) 48 | end 49 | 50 | return setmetatable(_M, { __call = function(_, ...) return new(...) end }) 51 | 52 | -- vim: et:sw=4:ts=8:sts=4:tw=80 53 | -------------------------------------------------------------------------------- /lib/lousy/widget/uri.lua: -------------------------------------------------------------------------------- 1 | --- Web page URI - status bar widget. 2 | -- 3 | -- Shows the URI of the current web page. If a link is hovered over with 4 | -- the mouse, the target URI of that link will be shown temporarily. 5 | -- 6 | -- @module lousy.widget.uri 7 | -- @copyright 2017 Aidan Holm 8 | -- @copyright 2010 Mason Larobina 9 | 10 | local _M = {} 11 | 12 | local webview = require("webview") 13 | local lousy = require("lousy") 14 | local theme = lousy.theme.get() 15 | local wc = require("lousy.widget.common") 16 | 17 | local widgets = { 18 | update = function (w, uri, link) 19 | local text = (link and "Link: " .. link) or (w.view and w.view.uri) or "about:blank" 20 | uri.text = lousy.util.escape(text) 21 | end, 22 | } 23 | 24 | webview.add_signal("init", function (view) 25 | view:add_signal("property::uri", function (v) 26 | local w = webview.window(v) 27 | if w and w.view == v then 28 | wc.update_widgets_on_w(widgets, w) 29 | end 30 | end) 31 | view:add_signal("link-hover", function (v, link) 32 | local w = webview.window(v) 33 | if w and w.view == v and link then 34 | wc.update_widgets_on_w(widgets, w, link) 35 | end 36 | end) 37 | view:add_signal("link-unhover", function (v) 38 | local w = webview.window(v) 39 | if w and w.view == v then 40 | wc.update_widgets_on_w(widgets, w) 41 | end 42 | end) 43 | view:add_signal("switched-page", function (v) 44 | wc.update_widgets_on_w(widgets, webview.window(v)) 45 | end) 46 | end) 47 | 48 | local function new() 49 | local uri = widget{type="label"} 50 | uri.selectable = true 51 | uri.fg = theme.uri_sbar_fg 52 | uri.font = theme.uri_sbar_font 53 | return wc.add_widget(widgets, uri) 54 | end 55 | 56 | return setmetatable(_M, { __call = function(_, ...) return new(...) end }) 57 | 58 | -- vim: et:sw=4:ts=8:sts=4:tw=80 59 | -------------------------------------------------------------------------------- /lib/lousy/widget/zoom.lua: -------------------------------------------------------------------------------- 1 | --- Web page zoom level - status bar widget. 2 | -- 3 | -- Shows the zoom levle of the current web page as a percentage. 4 | -- 5 | -- @module lousy.widget.zoom 6 | -- @copyright 2017 Aidan Holm 7 | -- @copyright 2014 Justin Forest 8 | 9 | local webview = require("webview") 10 | local lousy = require("lousy") 11 | local theme = lousy.theme.get() 12 | local wc = require("lousy.widget.common") 13 | local settings = require("settings") 14 | 15 | local _M = {} 16 | 17 | --- Format string which defines the appearance of the widget. 18 | -- This is passed to `string.format` the the zoom level as a numerical argument. 19 | -- @type string 20 | -- @readwrite 21 | _M.format = "[zoom:%d%%]" 22 | 23 | local widgets = { 24 | update = function (w, zoom) 25 | local zl = w.view.zoom_level 26 | if zl == settings.webview.zoom_level/100 then 27 | zoom:hide() 28 | else 29 | zoom:show() 30 | zoom.text = string.format(_M.format, zl * 100) 31 | end 32 | end, 33 | } 34 | 35 | webview.add_signal("init", function (view) 36 | -- Update widget when current page changes status 37 | view:add_signal("property::zoom_level", function (v) 38 | local w = webview.window(v) 39 | if w and w.view == v then 40 | wc.update_widgets_on_w(widgets, w) 41 | end 42 | end) 43 | view:add_signal("switched-page", function (v) 44 | wc.update_widgets_on_w(widgets, webview.window(v)) 45 | end) 46 | end) 47 | 48 | local function new() 49 | local zoom = widget{type="label"} 50 | zoom:hide() 51 | zoom.fg = theme.sbar_zoom_fg 52 | zoom.font = theme.sbar_zoom_font 53 | return wc.add_widget(widgets, zoom) 54 | end 55 | 56 | return setmetatable(_M, { __call = function(_, ...) return new(...) end }) 57 | 58 | -- vim: et:sw=4:ts=8:sts=4:tw=80 59 | -------------------------------------------------------------------------------- /lib/newtab_chrome.lua: -------------------------------------------------------------------------------- 1 | --- New tab page for luakit. 2 | -- 3 | -- This module provides , the luakit new 4 | -- tab page. This page is opened by default when opening a new tab without 5 | -- specifying a URL to open. 6 | -- 7 | -- # Customization 8 | -- 9 | -- The easiest way to customize what is shown at 10 | -- is to create a HTML file at the 11 | -- path specified by `newtab_chrome.new_tab_file`. By default, this is the 12 | -- `newtab.html` file located in the luakit data directory. 13 | -- 14 | -- If this file exists, then its contents will be used to provide the new tab 15 | -- page. Otherwise, the value of `newtab_chrome.new_tab_src` is used. 16 | -- 17 | -- # Files and Directories 18 | -- 19 | -- - The default path for the new-tab file is `newtab.html`, located in the luakit data directory. 20 | -- 21 | -- @module newtab_chrome 22 | -- @author Aidan Holm 23 | -- @copyright 2016 Aidan Holm 24 | 25 | local chrome = require "chrome" 26 | local theme = require "theme" 27 | local luakit = require "luakit" 28 | local settings = require "settings" 29 | 30 | local _M = {} 31 | 32 | --- Path to a HTML file to use for the new tab page. 33 | --The default value is `$XDG_DATA_DIR/luakit/newtab.html`. 34 | -- @type string 35 | -- @readwrite 36 | _M.new_tab_file = luakit.data_dir .. "/newtab.html" 37 | 38 | --- HTML string to use for the new tab page, if no HTML file is specified. 39 | -- The default value produces a page with no content and a single solid 40 | -- background color. `theme.bg` is used as the background color. 41 | -- @type string 42 | -- @readwrite 43 | _M.new_tab_src = ([==[ 44 | 45 | New Tab 46 | 47 | 48 | ]==]):gsub("{bgcolor}", theme.bg) 49 | 50 | local function load_file_contents(file) 51 | if not file then return nil end 52 | local f = io.open(file, "rb") 53 | if not f then return nil end 54 | local content = f:read("*all") 55 | f:close() 56 | return content 57 | end 58 | 59 | chrome.add("newtab", function () 60 | return load_file_contents(_M.new_tab_file) or _M.new_tab_src 61 | end) 62 | 63 | luakit.idle_add(function () 64 | local undoclose = package.loaded.undoclose 65 | if not undoclose then return end 66 | undoclose.add_signal("save", function (view) 67 | local uri, hist = view.uri or "", view.history 68 | if uri:match("^luakit://newtab/?") and #hist.items == 1 then 69 | return false 70 | end 71 | end) 72 | end) 73 | 74 | require "window" 75 | settings.window.new_tab_page = "luakit://newtab/" 76 | 77 | return _M 78 | 79 | -- vim: et:sw=4:ts=8:sts=4:tw=80 80 | -------------------------------------------------------------------------------- /lib/open_editor.lua: -------------------------------------------------------------------------------- 1 | --- Edit the contents of text inputs in an external editor. 2 | -- 3 | -- This module allows you to edit the contents of the currently focused 4 | -- text input in your preferred text editor. The focused text input is 5 | -- disabled, and a text editor window will open with the current input 6 | -- contents. After you have finished editing, save the file and quit the 7 | -- editor; the text input will be enabled and its contents will be set 8 | -- to that of the saved file. 9 | -- 10 | -- @module open_editor 11 | 12 | local modes = require("modes") 13 | local editor = require("editor") 14 | local add_binds = modes.add_binds 15 | 16 | local _M = {} 17 | 18 | local function edit_externally(w) 19 | local time = os.time() 20 | local marker = "luakit_extedit_" .. time 21 | local file = luakit.cache_dir .. "/" .. marker .. ".txt" 22 | 23 | local function editor_callback() 24 | local f = io.open(file, "r") 25 | local s = f:read("*all") 26 | f:close() 27 | os.remove(file) 28 | -- Strip the string 29 | s = s:gsub("^%s*(.-)%s*$", "%1") 30 | -- Escape it but remove the quotes 31 | s = string.format("%q", s):sub(2, -2) 32 | -- lua escaped newlines (slash+newline) into js newlines (slash+n) 33 | s = s:gsub("\\\n", "\\n") 34 | w.view:eval_js(string.format([=[ 35 | var e = document.getElementsByClassName('%s'); 36 | if (1 == e.length && e[0].disabled) { 37 | e[0].focus(); 38 | e[0].value = "%s"; 39 | e[0].disabled = false; 40 | e[0].className = e[0].className.replace(/\b %s\b/,''); 41 | } 42 | ]=], marker, s, marker), { no_return = true }) 43 | end 44 | 45 | w.view:eval_js(string.format([=[ 46 | var e = document.activeElement; 47 | if (e && ('TEXTAREA' === e.tagName || 'text' === e.type)) { 48 | var s = e.value; 49 | e.className += " %s"; 50 | e.disabled = true; 51 | e.value = 'Editing externally...'; 52 | s; 53 | } else 'false'; 54 | ]=], marker, file), { callback = function(s) 55 | if "false" ~= s then 56 | local f = io.open(file, "w") 57 | f:write(s) 58 | f:flush() 59 | f:close() 60 | editor.edit(file, 1, editor_callback) 61 | end 62 | end }) 63 | end 64 | 65 | add_binds("insert", { 66 | { "", "Edit currently focused input in external editor.", edit_externally }, 67 | }) 68 | 69 | return _M 70 | 71 | -- vim: et:sw=4:ts=8:sts=4:tw=80 72 | -------------------------------------------------------------------------------- /lib/referer_control_wm.lua: -------------------------------------------------------------------------------- 1 | --- Only send Referer header if coming from the same domain - web module. 2 | -- 3 | -- The Referer HTTP header is sent automatically to websites to inform them of 4 | -- the referring website; i.e. the website that you were just on. This allows 5 | -- website owners to see where web traffic is coming from, but can also be a 6 | -- privacy concern. 7 | -- 8 | -- To help mitigate this concern, this module prevents this information 9 | -- from being sent whenever you navigate between two different domains. 10 | -- For example, if you navigate from `https://example.com/test/` to 11 | -- `https://google.com`, no Referer hreader will be sent. If you navigate 12 | -- from `https://example.com/test/` to `https://example.com/`, however, the 13 | -- Referer header will be sent. This is because some websites depend on 14 | -- this functionality. 15 | -- 16 | -- *Note: the word 'referer' is intentionally misspelled for historic reasons.* 17 | -- 18 | -- # Usage 19 | -- 20 | -- As this is a web module, it will not function if loaded on the main UI Lua 21 | -- process through `require()`. Instead, it should be loaded with 22 | -- `require_web_module()`: 23 | -- 24 | -- require_web_module("referer_control_wm") 25 | -- 26 | -- @module referer_control_wm 27 | -- @copyright 2016 Aidan Holm 28 | 29 | local _M = {} 30 | 31 | local function domain_from_uri(uri) 32 | local domain = (uri and string.match(string.lower(uri), "^%a+://([^/]*)/?")) 33 | -- Strip leading www. www2. etc 34 | domain = string.match(domain or "", "^www%d?%.(.+)") or domain 35 | return domain or "" 36 | end 37 | 38 | luakit.add_signal("page-created", function(page) 39 | page:add_signal("send-request", function(p, _, headers) 40 | if not headers.Referer then return end 41 | if domain_from_uri(p.uri) ~= domain_from_uri(headers.Referer) then 42 | msg.verbose("Removing referer '%s'", headers.Referer) 43 | headers.Referer = nil 44 | end 45 | end) 46 | end) 47 | 48 | return _M 49 | 50 | -- vim: et:sw=4:ts=8:sts=4:tw=80 51 | -------------------------------------------------------------------------------- /lib/select.lua: -------------------------------------------------------------------------------- 1 | --- Select a page element with a visual interface. 2 | -- 3 | -- This module allows you to change the style of hints used to hint elements for 4 | -- selection in `follow` mode, as well as other modes that use the visual hint 5 | -- overlay. 6 | -- 7 | -- @module select 8 | -- @copyright 2017 Aidan Holm 9 | 10 | local _M = {} 11 | 12 | local wrapped = { label_maker = nil } 13 | 14 | --- @property label_maker 15 | -- Function that describes how to generate labels for hints. In order to modify 16 | -- the hint label style, set this field to a function that takes one parameter, 17 | -- a table of chainable hint label style functions, and returns a chained set of 18 | -- these functions. 19 | -- 20 | -- # Example usage: 21 | -- 22 | -- local select = require "select" 23 | -- select.label_maker = function (s) 24 | -- return s.sort(s.reverse(s.charset("asdfqwerzxcv"))) 25 | -- end 26 | -- 27 | -- @readwrite 28 | -- @default nil 29 | -- @type function 30 | 31 | local wm = require_web_module("select_wm") 32 | 33 | luakit.add_signal("web-extension-created", function (view) 34 | if wrapped.label_maker then 35 | wm:emit_signal(view, "set_label_maker", wrapped.label_maker) 36 | end 37 | end) 38 | 39 | local mt = { 40 | __index = wrapped, 41 | __newindex = function (_, k, v) 42 | assert(type(v) == "function", "property 'label_maker' must be a function") 43 | if k == "label_maker" then 44 | wrapped.label_maker = v 45 | wm:emit_signal("set_label_maker", v) 46 | end 47 | end, 48 | } 49 | 50 | return setmetatable(_M, mt) 51 | 52 | -- vim: et:sw=4:ts=8:sts=4:tw=80 53 | -------------------------------------------------------------------------------- /lib/vertical_tabs.lua: -------------------------------------------------------------------------------- 1 | --- UI mod: vertical tabs. 2 | -- 3 | -- This module moves the tab bar to the side. 4 | -- 5 | -- @module vertical_tabs 6 | -- @copyright 2017 Aidan Holm 7 | 8 | local _M = {} 9 | 10 | local window = require("window") 11 | local lousy = require("lousy") 12 | local settings = require("settings") 13 | 14 | window.add_signal("build", function (w) 15 | -- Replace the existing tablist with a vertical one 16 | w.tablist:destroy() 17 | w.tablist = lousy.widget.tablist(w.tabs, "vertical") 18 | 19 | -- Add a paned widget: tablist on left, repack w.tabs on right 20 | local paned = widget{type="hpaned"} 21 | paned:pack1(w.tablist.widget, { resize = false, shrink = true }) 22 | w.tabs.parent.child = nil 23 | paned:pack2(w.tabs) 24 | paned.position = settings.vertical_tabs.sidebar_width 25 | 26 | w.menu_tabs.child = paned 27 | end) 28 | 29 | settings.register_settings({ 30 | ["vertical_tabs.sidebar_width"] = { 31 | type = "number", min = 0, 32 | default = 200, 33 | }, 34 | }) 35 | 36 | settings.migrate_global("vertical_tabs.sidebar_width", "vertical_tab_width") 37 | 38 | return _M 39 | 40 | -- vim: et:sw=4:ts=8:sts=4:tw=80 41 | -------------------------------------------------------------------------------- /lib/viewpdf.lua: -------------------------------------------------------------------------------- 1 | --- Automatic PDF viewing. 2 | -- 3 | -- This module automatically downloads PDF files to the luakit cache directory, 4 | -- and opens them with `xdg-open`. 5 | -- 6 | -- @module viewpdf 7 | -- @copyright 2016 Aidan Holm 8 | 9 | local downloads = require("downloads") 10 | 11 | local _M = {} 12 | 13 | downloads.add_signal("download-location", function(_, filename, mime) 14 | if mime == "application/pdf" then 15 | local dir = luakit.cache_dir .. "/viewpdf/" 16 | 17 | local mode = lfs.attributes(dir, "mode") 18 | if mode == nil then 19 | assert(lfs.mkdir(dir)) 20 | elseif mode ~= "directory" then 21 | error("Cannot create directory " .. dir) 22 | end 23 | 24 | return dir .. filename 25 | end 26 | end) 27 | 28 | downloads.add_signal("download::status", function(dl) 29 | if dl.mime_type == "application/pdf" and dl.status == "finished" then 30 | downloads.do_open(dl) 31 | end 32 | end) 33 | 34 | downloads.add_signal("open-file", function (file, mime_type) 35 | if mime_type == "application/pdf" then 36 | luakit.spawn(string.format("xdg-open %q", file)) 37 | return true 38 | end 39 | end) 40 | 41 | return _M 42 | 43 | -- vim: et:sw=4:ts=8:sts=4:tw=80 44 | -------------------------------------------------------------------------------- /lib/webinspector.lua: -------------------------------------------------------------------------------- 1 | --- Bindings for the web inspector. 2 | -- 3 | -- This module enables developer extras for luakit's web views, and adds a 4 | -- command to show/hide the WebKit web inspector. 5 | -- 6 | -- @module webinspector 7 | -- @copyright 2012 Fabian Streitel 8 | -- @copyright 2012 Mason Larobina 9 | 10 | local webview = require("webview") 11 | local modes = require("modes") 12 | local add_cmds = modes.add_cmds 13 | 14 | local _M = {} 15 | 16 | webview.add_signal("init", function (view) 17 | view.enable_developer_extras = true 18 | end) 19 | 20 | add_cmds({ 21 | { ":in[spect]", "Open the DOM inspector.", function (w, o) 22 | local v = w.view 23 | if o.bang then -- "inspect!" toggles inspector 24 | (v.inspector and v.close_inspector or v.show_inspector)(v) 25 | else 26 | w.view:show_inspector() 27 | end 28 | end }, 29 | }) 30 | 31 | return _M 32 | 33 | -- vim: et:sw=4:ts=8:sts=4:tw=80 34 | -------------------------------------------------------------------------------- /lib/webview_wm.lua: -------------------------------------------------------------------------------- 1 | -- Webview widget wrapper - web module. 2 | -- 3 | -- The webview module wraps the webview widget provided by luakit, adding 4 | -- several convenience APIs and providing basic functionality. 5 | -- 6 | -- @submodule webview 7 | -- @copyright 2017 Aidan Holm 8 | -- @copyright 2012 Mason Larobina 9 | 10 | local ui = ipc_channel("webview_wm") 11 | 12 | ui:add_signal("load-finished", function(_, page) 13 | if not page then return end 14 | local doc = page.document 15 | 16 | -- do nothing if loaded document is not HTML 17 | if not doc.body then return end 18 | 19 | if page.uri:find("luakit://", 1, true) == 1 then 20 | doc.body:add_event_listener("click", true, function (event) 21 | if event.button ~= 0 then return end 22 | if event.target.tag_name ~= "A" then return end 23 | if (event.target.attr.href or ""):find("file://", 1, true) ~= 1 then return end 24 | 25 | ui:emit_signal("navigate", page.id, event.target.attr.href) 26 | end) 27 | end 28 | 29 | end) 30 | 31 | -- vim: et:sw=4:ts=8:sts=4:tw=80 32 | -------------------------------------------------------------------------------- /log.h: -------------------------------------------------------------------------------- 1 | /* 2 | * log.h - logging functions 3 | * 4 | * Copyright © 2017 Aidan Holm 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #ifndef LUAKIT_LOG_H 22 | #define LUAKIT_LOG_H 23 | 24 | #include "common/log.h" 25 | 26 | void log_init(void); 27 | int log_level_from_string(log_level_t *out, const char *str); 28 | void log_set_verbosity(const char *group, log_level_t lvl); 29 | log_level_t log_get_verbosity(char *group); 30 | char * log_dump_queued_emissions(void); 31 | 32 | #endif 33 | 34 | // vim: ft=c:et:sw=4:ts=8:sts=4:tw=80 35 | -------------------------------------------------------------------------------- /luah.h: -------------------------------------------------------------------------------- 1 | /* 2 | * luah.h - Lua helper functions 3 | * 4 | * Copyright © 2010 Mason Larobina 5 | * Copyright © 2008-2009 Julien Danjou 6 | * 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. 11 | * 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. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | * 20 | */ 21 | 22 | #ifndef LUAKIT_LUAH_H 23 | #define LUAKIT_LUAH_H 24 | 25 | #include "common/luah.h" 26 | 27 | void luaH_init(); 28 | gboolean luaH_parserc(const gchar *, gboolean); 29 | gint luaH_mtnext(lua_State *, gint); 30 | 31 | void luaH_modifier_table_push(lua_State *, guint); 32 | void luaH_keystr_push(lua_State *, guint); 33 | 34 | #endif 35 | 36 | // vim: ft=c:et:sw=4:ts=8:sts=4:tw=80 37 | -------------------------------------------------------------------------------- /resources/icons/COPYING: -------------------------------------------------------------------------------- 1 | The following files are part of the Arc Icon Theme project, available at 2 | https://github.com/horst3180/arc-icon-theme, licensed under the GPLv3. 3 | See COPYING.GPLv3. 4 | 5 | resources/icons/tab-icon-chrome.png 6 | resources/icons/tab-icon-chrome@2x.png 7 | resources/icons/tab-icon-private.png 8 | resources/icons/tab-icon-private@2x.png 9 | 10 | The following files are modified files from the Arc Icon Theme project, 11 | available at https://github.com/horst3180/arc-icon-theme, licensed under 12 | the GPLv3. See COPYING.GPLv3. Modification date: 24 July 2017. 13 | 14 | resources/icons/tab-icon-page.png 15 | resources/icons/tab-icon-page@2x.png 16 | resources/icons/tab-icon-crash.png 17 | resources/icons/tab-icon-crash@2x.png 18 | resources/icons/tab-icon-error.png 19 | resources/icons/tab-icon-error@2x.png 20 | resources/icons/tab-icon-security-error.png 21 | resources/icons/tab-icon-security-error@2x.png 22 | -------------------------------------------------------------------------------- /resources/icons/tab-icon-chrome.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aidanholm/luakit/9798a1d9bb0598efeb07403b64a5b535dd34eff1/resources/icons/tab-icon-chrome.png -------------------------------------------------------------------------------- /resources/icons/tab-icon-chrome@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aidanholm/luakit/9798a1d9bb0598efeb07403b64a5b535dd34eff1/resources/icons/tab-icon-chrome@2x.png -------------------------------------------------------------------------------- /resources/icons/tab-icon-crash.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aidanholm/luakit/9798a1d9bb0598efeb07403b64a5b535dd34eff1/resources/icons/tab-icon-crash.png -------------------------------------------------------------------------------- /resources/icons/tab-icon-crash@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aidanholm/luakit/9798a1d9bb0598efeb07403b64a5b535dd34eff1/resources/icons/tab-icon-crash@2x.png -------------------------------------------------------------------------------- /resources/icons/tab-icon-error.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aidanholm/luakit/9798a1d9bb0598efeb07403b64a5b535dd34eff1/resources/icons/tab-icon-error.png -------------------------------------------------------------------------------- /resources/icons/tab-icon-error@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aidanholm/luakit/9798a1d9bb0598efeb07403b64a5b535dd34eff1/resources/icons/tab-icon-error@2x.png -------------------------------------------------------------------------------- /resources/icons/tab-icon-page.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aidanholm/luakit/9798a1d9bb0598efeb07403b64a5b535dd34eff1/resources/icons/tab-icon-page.png -------------------------------------------------------------------------------- /resources/icons/tab-icon-page@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aidanholm/luakit/9798a1d9bb0598efeb07403b64a5b535dd34eff1/resources/icons/tab-icon-page@2x.png -------------------------------------------------------------------------------- /resources/icons/tab-icon-private.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aidanholm/luakit/9798a1d9bb0598efeb07403b64a5b535dd34eff1/resources/icons/tab-icon-private.png -------------------------------------------------------------------------------- /resources/icons/tab-icon-private@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aidanholm/luakit/9798a1d9bb0598efeb07403b64a5b535dd34eff1/resources/icons/tab-icon-private@2x.png -------------------------------------------------------------------------------- /resources/icons/tab-icon-security-error.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aidanholm/luakit/9798a1d9bb0598efeb07403b64a5b535dd34eff1/resources/icons/tab-icon-security-error.png -------------------------------------------------------------------------------- /resources/icons/tab-icon-security-error@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aidanholm/luakit/9798a1d9bb0598efeb07403b64a5b535dd34eff1/resources/icons/tab-icon-security-error@2x.png -------------------------------------------------------------------------------- /tests/async/test_basic.lua: -------------------------------------------------------------------------------- 1 | --- Basic async test functions. 2 | -- 3 | -- @copyright 2017 Aidan Holm 4 | 5 | local T = {} 6 | local test = require "tests.lib" 7 | 8 | local window = widget{type="window"} 9 | local view = widget{type="webview"} 10 | window.child = view 11 | window:show() 12 | 13 | T.test_about_blank_loads_successfully = function () 14 | view.uri = "about:blank" 15 | test.wait_for_view(view) 16 | end 17 | 18 | return T 19 | 20 | -- vim: et:sw=4:ts=8:sts=4:tw=80 21 | -------------------------------------------------------------------------------- /tests/async/test_binds_api.lua: -------------------------------------------------------------------------------- 1 | --- Test binds APIs. 2 | -- 3 | -- @copyright 2017 Aidan Holm 4 | 5 | local assert = require "luassert" 6 | local lousy = require "lousy" 7 | 8 | local T = {} 9 | 10 | T.test_binds_are_called = function () 11 | local binds = {} 12 | local hit_count = 0 13 | local action = { func = function () hit_count = hit_count + 1 end } 14 | 15 | lousy.bind.add_bind(binds, "a", action) 16 | lousy.bind.add_bind(binds, "", action) 17 | lousy.bind.add_bind(binds, "", action) 18 | lousy.bind.add_bind(binds, "gg", action) 19 | lousy.bind.add_bind(binds, ":test", action) 20 | lousy.bind.add_bind(binds, ":test-short, :test-loooooooong", action) 21 | lousy.bind.add_bind(binds, ":", action) 22 | lousy.bind.add_bind(binds, "", action) 23 | lousy.bind.add_bind(binds, "", action) 24 | lousy.bind.add_bind(binds, "gT", action) 25 | lousy.bind.add_bind(binds, "-", action) 26 | lousy.bind.add_bind(binds, "", action) 27 | assert.equal(12, #binds) 28 | 29 | lousy.bind.hit(nil, binds, {}, "a", {}) 30 | assert.equal(1, hit_count) 31 | 32 | lousy.bind.hit(nil, binds, {"Control", "Shift"}, "C", {}) 33 | assert.equal(2, hit_count) 34 | 35 | local args = { buffer = "", enable_buffer = true } 36 | local _, newbuf = lousy.bind.hit(nil, binds, {}, "g", args) 37 | args.buffer = newbuf 38 | _, newbuf = lousy.bind.hit(nil, binds, {}, "g", args) 39 | args.buffer = newbuf 40 | assert.equal(3, hit_count) 41 | assert.equal(nil, args.buffer) 42 | 43 | lousy.bind.match_cmd(nil, binds, "test", {}) 44 | lousy.bind.match_cmd(nil, binds, "test-short", {}) 45 | lousy.bind.match_cmd(nil, binds, "test-loooooooong", {}) 46 | assert.equal(6, hit_count) 47 | 48 | lousy.bind.hit(nil, binds, {"Control"}, "a", {}) 49 | assert.equal(7, hit_count) 50 | 51 | lousy.bind.hit(nil, binds, {"Shift"}, ":", {}) 52 | assert.equal(8, hit_count) 53 | lousy.bind.hit(nil, binds, {}, ":", {}) 54 | assert.equal(9, hit_count) 55 | 56 | lousy.bind.hit(nil, binds, {"Shift"}, "Tab", {}) 57 | assert.equal(10, hit_count) 58 | 59 | lousy.bind.hit(nil, binds, {"Shift"}, 1, {}) 60 | assert.equal(11, hit_count) 61 | 62 | lousy.bind.hit(nil, binds, {}, "T", { buffer = "g", enable_buffer = true }) 63 | assert.equal(12, hit_count) 64 | 65 | lousy.bind.hit(nil, binds, {}, "-", {}) 66 | assert.equal(13, hit_count) 67 | 68 | lousy.bind.hit(nil, binds, {"Control", "Shift"}, "d", {}) 69 | assert.equal(14, hit_count) 70 | end 71 | 72 | return T 73 | 74 | -- vim: et:sw=4:ts=8:sts=4:tw=80 75 | -------------------------------------------------------------------------------- /tests/async/test_clib_regex.lua: -------------------------------------------------------------------------------- 1 | --- Test regex clib functionality. 2 | -- 3 | -- @copyright 2017 Aidan Holm 4 | 5 | local assert = require "luassert" 6 | 7 | local T = {} 8 | 9 | T.test_module = function () 10 | assert.is_table(regex) 11 | end 12 | 13 | T.test_regex_with_no_pattern_fails = function () 14 | assert.has_error(function () regex() end) 15 | end 16 | 17 | T.test_regex_matches = function () 18 | -- Empty string can match ^ and $ 19 | assert(regex{pattern="^"}:match("")) 20 | assert(regex{pattern="$"}:match("")) 21 | 22 | -- Case sensitive 23 | assert(not regex{pattern="a"}:match("A")) 24 | assert(regex{pattern="A"}:match("A")) 25 | end 26 | 27 | return T 28 | 29 | -- vim: et:sw=4:ts=8:sts=4:tw=80 30 | -------------------------------------------------------------------------------- /tests/async/test_clib_soup.lua: -------------------------------------------------------------------------------- 1 | --- Test luakit soup functionality. 2 | -- 3 | -- @copyright 2017 Aidan Holm 4 | 5 | local assert = require "luassert" 6 | 7 | local T = {} 8 | 9 | T.test_soup = function () 10 | assert.are.same(soup.parse_uri(""), nil) 11 | assert.are.same(soup.parse_uri("about:blank"), { 12 | scheme = "about", 13 | path = "blank", 14 | }) 15 | assert.are.same(soup.parse_uri("example.com"), { 16 | scheme = "http", 17 | host = "example.com", 18 | path = "/", 19 | port = 80, 20 | }) 21 | assert.are.same(soup.parse_uri("https://www.example.com:900"), { 22 | scheme = "https", 23 | host = "www.example.com", 24 | path = "/", 25 | port = 900, 26 | }) 27 | assert.are.same(soup.parse_uri("luakit://page"), { 28 | scheme = "luakit", 29 | host = "page", 30 | }) 31 | assert.are.same(soup.parse_uri("luakit://page/foo"), { 32 | scheme = "luakit", 33 | host = "page", 34 | path = "/foo", 35 | }) 36 | assert.are.same(soup.parse_uri("view-source:luakit://page/foo"), { 37 | scheme = "view-source", 38 | path = "luakit://page/foo", 39 | }) 40 | end 41 | 42 | T.test_set_proxy_uri = function () 43 | soup.proxy_uri = "default" 44 | assert.equal(soup.proxy_uri, "default") 45 | soup.proxy_uri = "no_proxy" 46 | assert.equal(soup.proxy_uri, "no_proxy") 47 | soup.proxy_uri = "no_proxy" 48 | assert.equal(soup.proxy_uri, "no_proxy") 49 | soup.proxy_uri = nil 50 | assert.equal(soup.proxy_uri, "default") 51 | assert.has_error(function () soup.proxy_uri = true end) 52 | end 53 | 54 | T.test_set_accept_policy = function () 55 | soup.accept_policy = "always" 56 | assert.equal("always", soup.accept_policy) 57 | soup.accept_policy = "never" 58 | assert.equal("never", soup.accept_policy) 59 | soup.accept_policy = "no_third_party" 60 | assert.equal("no_third_party", soup.accept_policy) 61 | end 62 | 63 | T.test_set_cookies_storage = function () 64 | local path = luakit.data_dir .. "/cookies2.db" 65 | soup.cookies_storage = path 66 | assert.equal(path, soup.cookies_storage) 67 | end 68 | 69 | return T 70 | 71 | -- vim: et:sw=4:ts=8:sts=4:tw=80 72 | -------------------------------------------------------------------------------- /tests/async/test_completion.lua: -------------------------------------------------------------------------------- 1 | --- Tests for the input completions module. 2 | -- 3 | -- @copyright 2017 Aidan Holm 4 | 5 | local T = {} 6 | local assert = require("luassert") 7 | 8 | uris = {"about:blank"} 9 | require "config.rc" 10 | 11 | local window = require "window" 12 | local w = assert(select(2, next(window.bywidget))) 13 | 14 | T.test_leaving_completion_restores_correct_input_text = function () 15 | local input = w.ibar.input 16 | 17 | w:enter_cmd(":tab") 18 | w:set_mode("completion") 19 | w.menu:move_up() 20 | assert.equal(":tab", input.text) 21 | 22 | input.text = ":adbl" 23 | w.menu:move_down() 24 | w.menu:move_up() 25 | assert.equal(":adbl", input.text) 26 | end 27 | 28 | return T 29 | 30 | -- vim: et:sw=4:ts=8:sts=4:tw=80 31 | -------------------------------------------------------------------------------- /tests/async/test_config.lua: -------------------------------------------------------------------------------- 1 | --- Test that the default config works. 2 | -- 3 | -- @copyright 2017 Aidan Holm 4 | 5 | local T = {} 6 | 7 | T.test__config_rc_loads_successfully = function () 8 | require "config.rc" 9 | end 10 | 11 | return T 12 | 13 | -- vim: et:sw=4:ts=8:sts=4:tw=80 14 | -------------------------------------------------------------------------------- /tests/async/test_http_test_server.lua: -------------------------------------------------------------------------------- 1 | --- Tests the http test server. 2 | -- 3 | -- @copyright 2017 Aidan Holm 4 | 5 | local T = {} 6 | local test = require "tests.lib" 7 | 8 | 9 | T.test_http_server_returns_file_contents = function () 10 | -- Read file contents 11 | local f = assert(io.open("tests/html/hello_world.html", "rb")) 12 | local contents = f:read("*a") or "" 13 | f:close() 14 | 15 | -- Load URI and wait for completion 16 | local view = widget{type="webview"} 17 | view.uri = test.http_server() .. "hello_world.html" 18 | test.wait_for_view(view) 19 | 20 | -- Wrap view.source get in another coroutine, since auto-suspending the 21 | -- test coroutine confuses the test runner 22 | coroutine.wrap(function () 23 | test.continue(view:get_source()) 24 | end)() 25 | local source = test.wait() 26 | 27 | assert(source == contents, "HTTP server returned wrong content for file") 28 | end 29 | 30 | return T 31 | 32 | -- vim: et:sw=4:ts=8:sts=4:tw=80 33 | -------------------------------------------------------------------------------- /tests/async/test_image_css.lua: -------------------------------------------------------------------------------- 1 | --- Test image CSS. 2 | -- 3 | -- @copyright 2017 Aidan Holm 4 | 5 | local assert = require "luassert" 6 | local test = require "tests.lib" 7 | local lousy = require "lousy" 8 | 9 | local T = {} 10 | 11 | local window = widget{type="window"} 12 | local view = widget{type="webview"} 13 | window.child = view 14 | window:show() 15 | 16 | -- Stub out webview module 17 | package.loaded.webview = lousy.signal.setup({}, true) 18 | local image_css = require("image_css") 19 | package.loaded.webview.emit_signal("init", view) 20 | 21 | local view_wait_for_status = function (v, status) 22 | repeat 23 | local _, s, uri, err = test.wait_for_signal(v, "load-status", 1000) 24 | if s == "failed" then 25 | local fmt = "tests.wait_for_view() failed loading '%s': %s" 26 | local msg = fmt:format(uri, err) 27 | assert(false, msg) 28 | end 29 | until s == status 30 | end 31 | 32 | T.test_image_css = function () 33 | local image_uri = test.http_server() .. "image_css/image.png" 34 | local page_uri = test.http_server() .. "image_css/default.html" 35 | local image_ss = image_css.stylesheet 36 | 37 | -- Load HTML page: stylesheet must be inactive 38 | view.uri = page_uri 39 | view_wait_for_status(view, "committed") 40 | assert.is_false(view.stylesheets[image_ss]) 41 | 42 | -- Load image page: stylesheet must be active 43 | view.uri = image_uri 44 | view_wait_for_status(view, "committed") 45 | assert.is_true(view.stylesheets[image_ss]) 46 | 47 | view:go_back(1) 48 | view_wait_for_status(view, "committed") 49 | assert.is_false(view.stylesheets[image_ss]) 50 | 51 | view:go_forward(1) 52 | view_wait_for_status(view, "committed") 53 | assert.is_true(view.stylesheets[image_ss]) 54 | 55 | view:go_back(1) 56 | view_wait_for_status(view, "committed") 57 | assert.is_false(view.stylesheets[image_ss]) 58 | end 59 | 60 | return T 61 | 62 | -- vim: et:sw=4:ts=8:sts=4:tw=80 63 | -------------------------------------------------------------------------------- /tests/async/test_lua_files_load_successfully.lua: -------------------------------------------------------------------------------- 1 | --- Test that all files in config/ and lib/ can be included. 2 | -- 3 | -- @copyright 2017 Aidan Holm 4 | 5 | local test = require("tests.lib") 6 | 7 | local T = {} 8 | 9 | T.test_all_lua_files_load_successfully = function () 10 | local exclude_files = { "config/rc.lua", "_wm%.lua$", "unique_instance%.lua" } 11 | local files = test.find_files({"config/", "lib/"}, ".+%.lua$", exclude_files) 12 | 13 | require "unique_instance" 14 | for _, file in ipairs(files) do 15 | local pkg = file:gsub("^%a+/", ""):gsub("%.lua$", ""):gsub("/", ".") 16 | require(pkg) 17 | end 18 | 19 | -- Wait for config file to finish loading 20 | luakit.idle_add(test.continue) 21 | test.wait() 22 | end 23 | 24 | return T 25 | 26 | -- vim: et:sw=4:ts=8:sts=4:tw=80 27 | -------------------------------------------------------------------------------- /tests/async/test_memory_leaks.lua: -------------------------------------------------------------------------------- 1 | --- Check for some memory leaks. 2 | -- 3 | -- @copyright 2017 Aidan Holm 4 | 5 | uris = {"about:blank"} 6 | require "config.rc" 7 | 8 | local window = require "window" 9 | local w = assert(select(2, next(window.bywidget))) 10 | 11 | local T = {} 12 | 13 | T.test_webview_from_closed_tab_is_released = function () 14 | local refs = setmetatable({}, { __mode = "k" }) 15 | refs[w.view] = true 16 | w:close_tab() 17 | for _=1,100 do collectgarbage() end 18 | assert(not next(refs), "webview widget not collected") 19 | end 20 | 21 | return T 22 | 23 | -- vim: et:sw=4:ts=8:sts=4:tw=80 24 | -------------------------------------------------------------------------------- /tests/async/test_module_binds_have_descriptions.lua: -------------------------------------------------------------------------------- 1 | --- Ensure all module bindings have descriptions. 2 | -- 3 | -- @copyright 2017 Aidan Holm 4 | 5 | local test = require("tests.lib") 6 | local lousy = require("lousy") 7 | 8 | local T = {} 9 | 10 | local modes = require "modes" 11 | 12 | local clear_all_mode_bindings = function () 13 | local mode_list = modes.get_modes() 14 | for mode_name in pairs(mode_list) do 15 | local mode = modes.get_mode(mode_name) 16 | mode.binds = nil 17 | end 18 | end 19 | 20 | local get_mode_bindings_for_module = function (mod) 21 | -- First require() loads the module and all dependencies 22 | -- Second require() loads just the module 23 | require(mod) 24 | clear_all_mode_bindings() 25 | package.loaded[mod] = nil 26 | require(mod) 27 | 28 | local ret = {} 29 | 30 | local mode_list = modes.get_modes() 31 | for mode_name in pairs(mode_list) do 32 | local mode = modes.get_mode(mode_name) 33 | for _, m in pairs(mode.binds or {}) do 34 | local b, a = unpack(m) 35 | table.insert(ret, { 36 | name = lousy.bind.bind_to_string(b), 37 | desc = a.desc, 38 | }) 39 | end 40 | end 41 | 42 | return ret 43 | end 44 | 45 | local function add_file_error(errors, file, error, ...) 46 | table.insert(errors, { file = file, err = string.format(error, ...) }) 47 | end 48 | 49 | T.test_module_binds_have_descriptions = function () 50 | local files = test.find_files({"lib/"}, ".+%.lua$", {"_wm%.lua$", "modes%.lua", "unique_instance%.lua"}) 51 | 52 | local errors = {} 53 | 54 | for _, file in ipairs(files) do 55 | local pkg = file:gsub("^%a+/", ""):gsub("%.lua$", ""):gsub("/", ".") 56 | for _, b in ipairs(get_mode_bindings_for_module(pkg)) do 57 | if not b.desc or b.desc == "" then 58 | add_file_error(errors, file, "No description for binding %s", b.name) 59 | end 60 | if b.desc and not b.desc:match("%.$") then 61 | add_file_error(errors, file, "Description for binding %s doesn't end in a full stop.", b.name) 62 | end 63 | if b.desc and b.desc:match("^%l") then 64 | add_file_error(errors, file, "Description for binding %s isn't capitalized.", b.name) 65 | end 66 | end 67 | end 68 | 69 | if #errors > 0 then 70 | error("Some bindings are missing descriptions:\n" .. test.format_file_errors(errors)) 71 | end 72 | end 73 | 74 | return T 75 | 76 | -- vim: et:sw=4:ts=8:sts=4:tw=80 77 | -------------------------------------------------------------------------------- /tests/async/test_scroll.lua: -------------------------------------------------------------------------------- 1 | --- Test page scrolling. 2 | -- 3 | -- @copyright 2017 Aidan Holm 4 | 5 | local T = {} 6 | local test = require "tests.lib" 7 | local assert = require "luassert" 8 | 9 | uris = { test.http_server() .. "scroll.html" } 10 | require "config.rc" 11 | 12 | local window = require "window" 13 | local w = assert(select(2, next(window.bywidget))) 14 | 15 | T.test_scrolling_works = function () 16 | test.wait_for_view(w.view) 17 | 18 | -- Fetch height of document body 19 | w.view:eval_js("document.body.getClientRects()[0].height", { callback = test.continue }) 20 | local doc_height = test.wait() 21 | 22 | local get_scroll_y = function () 23 | w.view:eval_js("window.scrollY", { callback = test.continue }) 24 | return test.wait() 25 | end 26 | 27 | assert.is_equal(0, get_scroll_y(), 28 | "Scroll position should start at top.") 29 | 30 | w:scroll{ yrel = 100 } 31 | assert.is_equal(100, get_scroll_y(), 32 | "Relative scrolling failed") 33 | 34 | w:scroll{ yrel = -100 } 35 | assert.is_equal(0, get_scroll_y(), 36 | "Relative scrolling failed") 37 | 38 | w:scroll{ yrel = -100 } 39 | assert.is_equal(0, get_scroll_y(), 40 | "Scrolling didn't stop when already at end") 41 | 42 | w:scroll{ yrel = 100 } 43 | assert.is_equal(100, get_scroll_y(), 44 | "Relative scrolling after scrolling against scroll-end failed") 45 | 46 | 47 | w:scroll{ y = 0 } 48 | assert.is_equal(0, get_scroll_y(), 49 | "Scrolling to top failed") 50 | 51 | w:scroll{ y = -1 } 52 | -- Scrolling to bottom requires a JS roundtrip to get document height 53 | -- first, so wait until that's finished before continuing... 54 | test.wait_until(function () return w.view.scroll.y > 0 end) 55 | assert.is_equal(doc_height - w.view.height, get_scroll_y(), 56 | "Scrolling to bottom failed") 57 | 58 | 59 | w:scroll{ ypct = 0 } 60 | test.wait_until(function () return w.view.scroll.y == 0 end) 61 | 62 | w:scroll{ ypct = 100 } 63 | test.wait_until(function () return w.view.scroll.y > 0 end) 64 | assert.is_equal(doc_height - w.view.height, get_scroll_y(), 65 | "Scrolling to 100% failed") 66 | end 67 | 68 | return T 69 | 70 | -- vim: et:sw=4:ts=8:sts=4:tw=80 71 | -------------------------------------------------------------------------------- /tests/async/test_settings.lua: -------------------------------------------------------------------------------- 1 | --- Test settings. 2 | -- 3 | -- @copyright 2017 Aidan Holm 4 | 5 | local assert = require "luassert" 6 | 7 | local settings = require "settings" 8 | 9 | local T = {} 10 | 11 | T.test_settings = function () 12 | assert.is_table(settings) 13 | 14 | settings.register_settings({ 15 | ["test.setting.with.long.path"] = { 16 | default = "foo", 17 | }, 18 | ["foo.bar"] = {}, 19 | }) 20 | 21 | assert.equal(settings.test.setting.with.long.path, "foo") 22 | settings.test.setting.with.long.path = "bar" 23 | assert.equal(settings.test.setting.with.long.path, "bar") 24 | assert.has_error(function () settings.test.setting = "baz" end) 25 | 26 | assert.has_error(function () settings.non_existent_setting = 1 end) 27 | assert.has_error(function () return settings.on["foo"].on["foo"] end) 28 | 29 | settings.foo.bar = 1 30 | assert.equal(settings.foo.bar, 1) 31 | settings.on["example.com"].foo.bar = 2 32 | assert.equal(settings.foo.bar, 1) 33 | assert.equal(settings.on["example.com"].foo.bar, 2) 34 | assert.equal(settings.on[".com"].foo.bar, nil) 35 | 36 | assert.equal(settings.get_setting_for_uri("example.com", "foo.bar"), 2) 37 | assert.equal(settings.get_setting_for_uri(".com", "foo.bar"), nil) 38 | end 39 | 40 | return T 41 | 42 | -- vim: et:sw=4:ts=8:sts=4:tw=80 43 | -------------------------------------------------------------------------------- /tests/async/test_widget.lua: -------------------------------------------------------------------------------- 1 | --- Test widget library. 2 | -- 3 | -- @copyright 2017 Aidan Holm 4 | 5 | local assert = require "luassert" 6 | 7 | local T = {} 8 | 9 | T.test_widget_of_invalid_type_fails = function () 10 | assert.has_error(function () widget{type="no_such_widget_type"} end) 11 | assert.has_error(function () widget{} end) 12 | end 13 | 14 | T.test_bin_widget_set_child = function () 15 | local bin = widget{type="window"} 16 | local child1 = widget{type="entry"} 17 | local child2 = widget{type="label"} 18 | 19 | assert.is_nil(bin.child) 20 | bin.child = child1 21 | assert.is_equal(bin.child, child1) 22 | bin.child = child2 23 | assert.is_equal(bin.child, child2) 24 | bin.child = nil 25 | assert.is_nil(bin.child) 26 | end 27 | 28 | T.test_webview_widget_privacy = function () 29 | local v = widget{type="webview"} 30 | assert.is_false(v.private) 31 | v = widget{type="webview", private=false} 32 | assert.is_false(v.private) 33 | v = widget{type="webview", private=true} 34 | assert.is_true(v.private) 35 | end 36 | 37 | return T 38 | 39 | -- vim: et:sw=4:ts=8:sts=4:tw=80 40 | -------------------------------------------------------------------------------- /tests/async/wrangle_paths.lua: -------------------------------------------------------------------------------- 1 | --- Test runner path wrangler. 2 | -- 3 | -- @script async.wrangle_paths 4 | -- @copyright 2017 Aidan Holm 5 | 6 | local system_paths, luakit_paths = {}, {} 7 | for path in string.gmatch(package.path, "[^;]+") do 8 | if not path:match("^%./") and not path:find("luakit") then 9 | table.insert(system_paths, path) 10 | elseif not path:match("^%./") and path:find("luakit_test_") then 11 | table.insert(luakit_paths, path) 12 | end 13 | end 14 | local rel_paths = { "./lib/?.lua", "./lib/?/init.lua", "./config/?.lua", "./config/?/init.lua", } 15 | system_paths = table.concat(system_paths, ";") 16 | rel_paths = table.concat(rel_paths, ";") 17 | luakit_paths = table.concat(luakit_paths, ";") 18 | package.path = string.format("./?.lua;%s;%s;%s", system_paths, rel_paths, luakit_paths) 19 | 20 | luakit.resource_path = "./resources" -- Don't use installed luakit when testing 21 | 22 | -- vim: et:sw=4:ts=8:sts=4:tw=80 23 | -------------------------------------------------------------------------------- /tests/html/hello_world.html: -------------------------------------------------------------------------------- 1 | Hello, world! -------------------------------------------------------------------------------- /tests/html/image_css/default.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Default 5 | 6 | 7 | Just an empty page. 8 | 9 | 10 | -------------------------------------------------------------------------------- /tests/html/image_css/image.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aidanholm/luakit/9798a1d9bb0598efeb07403b64a5b535dd34eff1/tests/html/image_css/image.png -------------------------------------------------------------------------------- /tests/html/scroll.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /tests/html/undoclose_page.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | undoclose_page 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /tests/priv.lua: -------------------------------------------------------------------------------- 1 | --- Utilities for use in tests. 2 | -- 3 | -- @module tests.util 4 | -- @copyright 2017 Aidan Holm 5 | 6 | local M = {} 7 | 8 | function M.load_test_file(test_file) 9 | local ok, ret = pcall(dofile, test_file) 10 | if not ok then 11 | return nil, ret 12 | end 13 | assert(type(ret) == "table") 14 | 15 | for test_name, func in pairs(ret) do 16 | assert(type(test_name) == "string") 17 | assert(type(func) == "function" or type(func) == "thread") 18 | end 19 | 20 | return ret 21 | end 22 | 23 | return M 24 | 25 | -- vim: et:sw=4:ts=8:sts=4:tw=80 26 | -------------------------------------------------------------------------------- /tests/style/test_common.lua: -------------------------------------------------------------------------------- 1 | local test = require "tests.lib" 2 | 3 | local T = {} 4 | 5 | function T.test_no_globalconf_in_common() 6 | local has_globalconf = {} 7 | local file_list = test.find_files("common", "%.[ch]$") 8 | for _, file in ipairs(file_list) do 9 | -- Get file contents 10 | local f = assert(io.open(file, "r")) 11 | local contents = f:read("*all") 12 | f:close() 13 | if contents:match("globalconf") then 14 | table.insert(has_globalconf, file) 15 | end 16 | end 17 | 18 | if #has_globalconf > 0 then 19 | local err = {} 20 | for _, file in ipairs(has_globalconf) do 21 | err[#err+1] = " " .. file 22 | end 23 | error("Some files in common/ access globalconf:\n" .. table.concat(err, "\n")) 24 | end 25 | end 26 | 27 | return T 28 | 29 | -- vim: et:sw=4:ts=8:sts=4:tw=80 30 | -------------------------------------------------------------------------------- /tests/style/test_documentation.lua: -------------------------------------------------------------------------------- 1 | local test = require "tests.lib" 2 | 3 | local T = {} 4 | 5 | local function read_file(file) 6 | local f = assert(io.open(file, "r")) 7 | local contents = f:read("*all") 8 | f:close() 9 | return contents 10 | end 11 | 12 | function T.test_module_blurb_not_empty () 13 | local file_list = test.find_files({"lib", "doc/luadoc"}, "%.lua$", 14 | {"lib/lousy/widget/", "lib/lousy/init.lua", "lib/markdown.lua"}) 15 | 16 | local errors = {} 17 | for _, file in ipairs(file_list) do 18 | local header = read_file(file):gsub("\n\n.*", "") .. "\n" 19 | -- Strip heading line, empty lines, @-lines, DOCMACRO lines 20 | local desc = header:gsub("^%-%-%-.-\n", ""):gsub("%-%- *\n", "") 21 | desc = desc:gsub("-- *%@.-\n", ""):gsub("^%-%- *DOCMACRO.-\n", "") 22 | if not desc:match("^%-%-") then 23 | table.insert(errors, { file = file, err = "Missing documentation" }) 24 | end 25 | end 26 | 27 | if #errors > 0 then 28 | error("Some files do not have documentation:\n" .. test.format_file_errors(errors)) 29 | end 30 | end 31 | 32 | return T 33 | 34 | -- vim: et:sw=4:ts=8:sts=4:tw=80 35 | -------------------------------------------------------------------------------- /tests/style/test_widgets.lua: -------------------------------------------------------------------------------- 1 | local test = require "tests.lib" 2 | 3 | local T = {} 4 | 5 | function T.test_widgets_use_macros() 6 | local errors = {} 7 | 8 | local file_list = test.find_files("widgets", "%.c$", {"widgets/webview/", "widgets/common.c"}) 9 | for _, file in ipairs(file_list) do 10 | -- Get file contents 11 | local f = assert(io.open(file, "r")) 12 | local contents = f:read("*all") 13 | f:close() 14 | 15 | if not contents:find("LUAKIT_WIDGET_SIGNAL_COMMON") then 16 | table.insert(errors, { file = file, err = "Missing LUAKIT_WIDGET_SIGNAL_COMMON" }) 17 | end 18 | end 19 | 20 | if #errors > 0 then 21 | error("Some widget wrappers have errors:\n" .. test.format_file_errors(errors)) 22 | end 23 | end 24 | 25 | return T 26 | 27 | -- vim: et:sw=4:ts=8:sts=4:tw=80 28 | -------------------------------------------------------------------------------- /web_context.h: -------------------------------------------------------------------------------- 1 | /* 2 | * web_context.h - WebKit web context setup and handling 3 | * 4 | * Copyright © 2016 Aidan Holm 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #ifndef LUAKIT_WEB_CONTEXT_H 22 | #define LUAKIT_WEB_CONTEXT_H 23 | 24 | #include 25 | 26 | void web_context_init(void); 27 | void web_context_init_finish(void); 28 | WebKitWebContext *web_context_get(void); 29 | WebKitWebContext *web_context_get_private(void); 30 | guint web_context_process_limit_get(void); 31 | gboolean web_context_process_limit_set(guint limit); 32 | 33 | #endif 34 | 35 | // vim: ft=c:et:sw=4:ts=8:sts=4:tw=80 36 | -------------------------------------------------------------------------------- /widgets/spinner.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2016 Aidan Holm 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | * 17 | */ 18 | 19 | #include "luah.h" 20 | #include "widgets/common.h" 21 | 22 | static widget_t* 23 | luaH_checkspinner(lua_State *L, gint udx) 24 | { 25 | widget_t *w = luaH_checkwidget(L, udx); 26 | if (w->info->tok != L_TK_SPINNER) 27 | luaL_argerror(L, udx, "incorrect widget type (expected spinner)"); 28 | return w; 29 | } 30 | 31 | static gint 32 | luaH_spinner_start(lua_State *L) 33 | { 34 | widget_t *w = luaH_checkspinner(L, 1); 35 | gtk_spinner_start(GTK_SPINNER(w->widget)); 36 | return 0; 37 | } 38 | 39 | static gint 40 | luaH_spinner_stop(lua_State *L) 41 | { 42 | widget_t *w = luaH_checkspinner(L, 1); 43 | gtk_spinner_stop(GTK_SPINNER(w->widget)); 44 | return 0; 45 | } 46 | 47 | static gint 48 | luaH_spinner_index(lua_State *L, widget_t *w, luakit_token_t token) 49 | { 50 | gboolean active; 51 | switch(token) { 52 | LUAKIT_WIDGET_INDEX_COMMON(w) 53 | 54 | PB_CASE(STARTED, (g_object_get(G_OBJECT(w->widget), "active", &active, NULL), active)) 55 | PF_CASE(START, luaH_spinner_start) 56 | PF_CASE(STOP, luaH_spinner_stop) 57 | 58 | default: 59 | break; 60 | } 61 | return 0; 62 | } 63 | 64 | static gint 65 | luaH_spinner_newindex(lua_State *L, widget_t *w, luakit_token_t token) 66 | { 67 | switch(token) { 68 | LUAKIT_WIDGET_NEWINDEX_COMMON(w) 69 | 70 | default: 71 | break; 72 | } 73 | 74 | return luaH_object_property_signal(L, 1, token); 75 | } 76 | 77 | widget_t * 78 | widget_spinner(lua_State *UNUSED(L), widget_t *w, luakit_token_t UNUSED(token)) 79 | { 80 | w->index = luaH_spinner_index; 81 | w->newindex = luaH_spinner_newindex; 82 | 83 | w->widget = gtk_spinner_new(); 84 | 85 | g_object_connect(G_OBJECT(w->widget), 86 | LUAKIT_WIDGET_SIGNAL_COMMON(w) 87 | NULL); 88 | 89 | gtk_widget_show(w->widget); 90 | return w; 91 | } 92 | 93 | // vim: ft=c:et:sw=4:ts=8:sts=4:tw=80 94 | -------------------------------------------------------------------------------- /widgets/webview.h: -------------------------------------------------------------------------------- 1 | /* 2 | * widgets/webview.h - interfaces to webview functionality 3 | * 4 | * Copyright © 2016 Aidan Holm 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #ifndef LUAKIT_WIDGETS_WEBVIEW_H 22 | #define LUAKIT_WIDGETS_WEBVIEW_H 23 | 24 | #include 25 | #include "clib/widget.h" 26 | #include "common/ipc.h" 27 | 28 | widget_t* luaH_checkwebview(lua_State *L, gint udx); 29 | widget_t* webview_get_by_id(guint64 view_id); 30 | void webview_connect_to_endpoint(widget_t *w, ipc_endpoint_t *ipc); 31 | void webview_set_web_process_id(widget_t *w, pid_t pid); 32 | ipc_endpoint_t * webview_get_endpoint(widget_t *w); 33 | 34 | #endif 35 | 36 | // vim: ft=c:et:sw=4:ts=8:sts=4:tw=80 37 | -------------------------------------------------------------------------------- /widgets/webview/downloads.c: -------------------------------------------------------------------------------- 1 | /* 2 | * widgets/webview/downloads.c - webkit webview download functions 3 | * 4 | * Copyright © 2010-2011 Mason Larobina 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #include "clib/download.h" 22 | #include "clib/luakit.h" 23 | 24 | gboolean 25 | download_start_cb(WebKitWebContext* UNUSED(c), WebKitDownload *dl, gpointer UNUSED(user_data)) 26 | { 27 | WebKitWebView *dl_view = webkit_download_get_web_view(dl); 28 | widget_t *w = dl_view ? GOBJECT_TO_LUAKIT_WIDGET(dl_view) : NULL; 29 | 30 | lua_State *L = common.L; 31 | gint top = lua_gettop(L); 32 | luaH_download_push(L, dl); 33 | if (w) 34 | luaH_object_push(L, w->ref); 35 | else 36 | lua_pushnil(L); 37 | 38 | lua_class_t *luakit_class = luakit_lib_get_luakit_class(); 39 | gint ret = luaH_class_emit_signal(L, luakit_class, "download-start", 2, 1); 40 | gboolean handled = (ret && lua_toboolean(L, 2)); 41 | lua_settop(L, top); 42 | return handled; 43 | } 44 | 45 | // vim: ft=c:et:sw=4:ts=8:sts=4:tw=80 46 | -------------------------------------------------------------------------------- /widgets/webview/find_controller.c: -------------------------------------------------------------------------------- 1 | /* 2 | * widgets/webview/find_controller.c - WebKitFindController wrappers 3 | * 4 | * Copyright © 2012 Mason Larobina 5 | * Copyright © 2011-2012 Fabian Streitel 6 | * 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. 11 | * 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. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | * 20 | */ 21 | 22 | static void 23 | found_text_cb(WebKitFindController* UNUSED(find_controller), guint match_count, 24 | widget_t *w) 25 | { 26 | lua_State *L = common.L; 27 | luaH_object_push(L, w->ref); 28 | lua_pushinteger(L, match_count); 29 | luaH_object_emit_signal(L, -2, "found-text", 1, 0); 30 | lua_pop(L, 1); 31 | return; 32 | } 33 | 34 | static void 35 | failed_to_find_text_cb(WebKitFindController* UNUSED(find_controller), 36 | widget_t *w) 37 | { 38 | lua_State *L = common.L; 39 | luaH_object_push(L, w->ref); 40 | luaH_object_emit_signal(L, -1, "failed-to-find-text", 0, 0); 41 | lua_pop(L, 1); 42 | return; 43 | } 44 | 45 | // vim: ft=c:et:sw=4:ts=8:sts=4:tw=80 46 | --------------------------------------------------------------------------------