/* * Curses binding for Lua 5.1, 5.2 & 5.3. * * (c) Gary V. Vaughan 2013-2017 * (c) Reuben Thomas 2009-2012 * (c) Tiago Dionizio 2004-2007 * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*** Curses Window objects. The methods documented on this page are available on any Curses Window object, such as created by: stdscr = curses.initscr () window = curses.newwin (25, 80, 0, 0) @classmod curses.window */ #include "../teliva.h" #include "_helpers.c" #include "chstr.c" static const char *WINDOWMETA = "curses:window"; static void lc_newwin(lua_State *L, WINDOW *nw) { if (nw) { WINDOW **w = lua_newuserdata(L, sizeof(WINDOW*)); luaL_getmetatable(L, WINDOWMETA); lua_setmetatable(L, -2); *w = nw; } else { lua_pushliteral(L, "failed to create window"); lua_error(L); } } static WINDOW ** lc_getwin(lua_State *L, int offset) { WINDOW **w = (WINDOW**)luaL_checkudata(L, offset, WINDOWMETA); if (w == NULL) luaL_argerror(L, offset, "bad curses window"); return w; } static WINDOW * checkwin(lua_State *L, int offset) { WINDOW **w = lc_getwin(L, offset); if (*w == NULL) luaL_argerror(L, offset, "attempt to use closed curses window"); return *w; } /*** Unique string representation of a @{curses.window}. @function __tostring @treturn string unique string representation of the window object. */ static int W__tostring(lua_State *L) { WINDOW **w = lc_getwin(L, 1); char buff[34]; if (*w == NULL) strcpy(buff, "closed"); else sprintf(buff, "%p", lua_touserdata(L, 1)); lua_pushfstring(L, "curses window (%s)", buff); return 1; } /*** Free all the resources associated with a window. @function close @see delwin(3x) */ static int Wclose(lua_State *L) { WINDOW **w = lc_getwin(L,
getwtxt
*.log
int n @param[opt] changed @treturn bool `true`, if successful @see wtouchln(3x) */ static int Wtouchline(lua_State *L) { WINDOW *w = checkwin(L, 1); int y = checkint(L, 2); int n = checkint(L, 3); int changed; if (lua_isnoneornil(L, 4)) changed = TRUE; else changed = lua_toboolean(L, 4); return pushokresult(wtouchln(w, y, n, changed)); } /*** Has a particular window line changed since the last refresh? @function is_linetouched @int line @treturn bool `true`, if successful @see is_linetouched(3x) */ static int Wis_linetouched(lua_State *L) { WINDOW *w = checkwin(L, 1); int line = checkint(L, 2); return pushboolresult(is_linetouched(w, line)); } /*** Has a window changed since the last refresh? @function is_wintouched @treturn bool `true`, if successful @see is_wintouched(3x) */ static int Wis_wintouched(lua_State *L) { WINDOW *w = checkwin(L, 1); return pushboolresult(is_wintouched(w)); } /*** Fetch the cursor position. @function getyx @treturn int y coordinate of top line @treturn int x coordinate of left column @see getyx(3x) */ static int Wgetyx(lua_State *L) { WINDOW *w = checkwin(L, 1); int y, x; getyx(w, y, x); lua_pushinteger(L, y); lua_pushinteger(L, x); return 2; } /*** Fetch the parent-relative coordinates of a subwindow. @function getparyx @treturn int y coordinate of top line relative to parent window @treturn int x coordinate of left column relative to parent window @see getparyx(3x) */ static int Wgetparyx(lua_State *L) { WINDOW *w = checkwin(L, 1); int y, x; getparyx(w, y, x); lua_pushinteger(L, y); lua_pushinteger(L, x); return 2; } /*** Fetch the absolute top-left coordinates of a window. @function getbegyx @treturn int y coordinate of top line @treturn int x coordinate of left column @see getbegyx(3x) */ static int Wgetbegyx(lua_State *L) { WINDOW *w = checkwin(L, 1); int y, x; getbegyx(w, y, x); lua_pushinteger(L, y); lua_pushinteger(L, x); return 2; } /*** Fetch the absolute bottom-right coordinates of a window. @function getmaxyx @treturn int y coordinate of bottom line @treturn int x coordinate of right column @see getmaxyx(3x) */ static int Wgetmaxyx(lua_State *L) { WINDOW *w = checkwin(L, 1); int y, x; getmaxyx(w, y, x); --y; // set aside space for the menu bar lua_pushinteger(L, y); lua_pushinteger(L, x); return 2; } /*** Draw a border around a window. @function border @int[opt] ls @int[opt] rs @int[opt] ts @int[opt] bs @int[opt] tl @int[opt] tr @int[opt] bl @int[opt] br @treturn bool `true`, if successful @see wborder(3x) @usage win:border (curses.ACS_VLINE, curses.ACS_VLINE, curses.ACS_HLINE, curses.ACS_HLINE, curses.ACS_ULCORNER, curses.ACS_URCORNER, curses.ACS_LLCORNER, curses.ACS_LRCORNER) */ static int Wborder(lua_State *L) { WINDOW *w = checkwin(L, 1); chtype ls = optch(L, 2, 0); chtype rs = optch(L, 3, 0); chtype ts = optch(L, 4, 0); chtype bs = optch(L, 5, 0); chtype tl = optch(L, 6, 0); chtype tr = optch(L, 7, 0); chtype bl = optch(L, 8, 0); chtype br = optch(L, 9, 0); return pushokresult(wborder(w, ls, rs, ts, bs, tl, tr, bl, br)); } /*** Draw a box around a window. @function box @int verch @int horch @treturn bool `true`, if successful @see box(3x) @see border @usage win:box (curses.ACS_VLINE, curses.ACS_HLINE) */ static int Wbox(lua_State *L) { WINDOW *w = checkwin(L, 1); chtype verch = checkch(L, 2); chtype horch = checkch(L, 3); return pushokresult(box(w, verch, horch)); } /*** Draw a row of characters from the current cursor position. @function hline @int ch @int n @treturn bool `true`, if successful @see whline(3x) @see mvhline @see vline @usage _, width = win:getmaxyx () win:hline (curses.ACS_HLINE, width - curs_x) */ static int Whline(lua_State *L) { WINDOW *w = checkwin(L, 1); chtype ch = checkch(L, 2); int n = checkint(L, 3); return pushokresult(whline(w, ch, n)); } /*** Draw a column of characters from the current cursor position. @function vline @int ch @int n @treturn bool `true`, if successful @see wvline(3x) @see hline @see mvvline */ static int Wvline(lua_State *L) { WINDOW *w = checkwin(L, 1); chtype ch = checkch(L, 2); int n = checkint(L, 3); return pushokresult(wvline(w, ch, n)); } /*** Move the cursor, then draw a row of characters from the new cursor position. @function mvhline @int y @int x @int ch @int n @treturn bool `true`, if successful @see mvwhline(3x) */ static int Wmvhline(lua_State *L) { WINDOW *w = checkwin(L, 1); int y = checkint(L, 2); int x = checkint(L, 3); chtype ch = checkch(L, 4); int n = checkint(L, 5); return pushokresult(mvwhline(w, y, x, ch, n)); } /*** Move the cursor, then draw a column of characters from the new cursor position. @function mvvline @int y @int x @int ch @int n @treturn bool `true`, if successful @see mvwvline(3x) */ static int Wmvvline(lua_State *L) { WINDOW *w = checkwin(L, 1); int y = checkint(L, 2); int x = checkint(L, 3); chtype ch = checkch(L, 4); int n = checkint(L, 5); return pushokresult(mvwvline(w, y, x, ch, n)); } /*** Write blanks to every character position in the window. @function erase @treturn bool `true`, if successful @see werase(3x) */ static int Werase(lua_State *L) { return pushokresult(werase(checkwin(L, 1))); } /*** Call @{erase} and then @{clearok}. @function clear @treturn bool `true`, if successful @see wclear(3x) */ static int Wclear(lua_State *L) { return pushokresult(wclear(checkwin(L, 1))); } /*** Write blanks to every character position after the cursor. @function clrtobot @treturn bool `true`, if successful @see wclrtobot(3x) */ static int Wclrtobot(lua_State *L) { return pushokresult(wclrtobot(checkwin(L, 1))); } /*** Write blanks from the cursor to the end of the current line. @function clrtoeol @treturn bool `true`, if successful @see wclrtoeol(3x) */ static int Wclrtoeol(lua_State *L) { return pushokresult(wclrtoeol(checkwin(L, 1))); } /*** Advance the cursor after writing a character at the old position. @function addch @int ch @treturn bool `true`, if successful @see waddch(3x) */ static int Waddch(lua_State *L) { WINDOW *w = checkwin(L, 1); chtype ch = checkch(L, 2); return pushokresult(waddch(w, ch)); } /*** Call @{move}, then @{addch}. @function mvaddch @int y @int x @int ch @treturn bool `true`, if successful @see mvwaddch(3x) */ static int Wmvaddch(lua_State *L) { WINDOW *w = checkwin(L, 1); int y = checkint(L, 2); int x = checkint(L, 3); chtype ch = checkch(L, 4); return pushokresult(mvwaddch(w, y, x, ch)); } /*** Call @{addch} then @{refresh}. @function echoch @int ch @treturn bool `true`, if successful @see wechochar(3x) */ static int Wechoch(lua_State *L) { WINDOW *w = checkwin(L, 1); chtype ch = checkch(L, 2); return pushokresult(wechochar(w, ch)); } /*** Copy a @{curses.chstr} starting at the current cursor position. @function addchstr @int chstr cs @int[opt] n @treturn bool `true`, if successful @see waddchnstr(3x) */ static int Waddchstr(lua_State *L) { WINDOW *w = checkwin(L, 1); int n = optint(L, 3, -1); chstr *cs = checkchstr(L, 2); if (n < 0 || n > (int) cs->len) n = cs->len; return pushokresult(waddchnstr(w, cs->str, n)); } /*** Call @{move} then @{addchstr}. @function mvaddchstr @int y @int x @int[opt] n @treturn bool `true`, if successful @see mvwaddchnstr(3x) */ static int Wmvaddchstr(lua_State *L) { WINDOW *w = checkwin(L, 1); int y = checkint(L, 2); int x = checkint(L, 3); int n = optint(L, 5, -1); chstr *cs = checkchstr(L, 4); if (n < 0 || n > (int) cs->len) n = cs->len; return pushokresult(mvwaddchnstr(w, y, x, cs->str, n)); } /*** Copy a Lua string starting at the current cursor position. @function addstr @string str @int[opt] n @treturn bool `true`, if successful @see waddnstr(3x) */ static int Waddstr(lua_State *L) { WINDOW *w = checkwin(L, 1); const char *str = luaL_checkstring(L, 2); int n = optint(L, 3, -1); return pushokresult(waddnstr(w, str, n)); } /*** Call @{move} then @{addstr}. @function mvaddstr @int y @int x @string str @int[opt] n @treturn bool `true`, if successful @see mvwaddnstr(3x) */ static int Wmvaddstr(lua_State *L) { WINDOW *w = checkwin(L, 1); int y = checkint(L, 2); int x = checkint(L, 3); const char *str = luaL_checkstring(L, 4); int n = optint(L, 5, -1); return pushokresult(mvwaddnstr(w, y, x, str, n)); } /*** Set the background attributes for subsequently written characters. @function wbkgdset @int ch @see wbkgdset(3x) */ static int Wwbkgdset(lua_State *L) { WINDOW *w = checkwin(L, 1); chtype ch = checkch(L, 2); wbkgdset(w, ch); return 0; } /*** Call @{wbkgdset} and then set the background of every position accordingly. @function wbkgd @int ch @treturn bool `true`, if successful @see wbkgd(3x) */ static int Wwbkgd(lua_State *L) { WINDOW *w = checkwin(L, 1); chtype ch = checkch(L, 2); return pushokresult(wbkgd(w, ch)); } /*** Fetch the current background attribute for the window. @function getbkgd @treturn int current window background attribute @see getbkgd(3x) @see wbkgd */ static int Wgetbkgd(lua_State *L) { return pushintresult(getbkgd(checkwin(L, 1))); } /*** Set the flush on interrupt behaviour for the window. @function intrflush @bool bf @treturn bool `true`, if successful @see intrflush(3x) */ static int Wintrflush(lua_State *L) { WINDOW *w = checkwin(L, 1); int bf = lua_toboolean(L, 2); return pushokresult(intrflush(w, bf)); } /*** Set the single value keypad keys behaviour for the window. @function keypad @bool[opt] on @treturn bool `true`, if successful @see keypad(3x) */ static int Wkeypad(lua_State *L) { WINDOW *w = checkwin(L, 1); int bf = lua_isnoneornil(L, 2) ? 1 : lua_toboolean(L, 2); return pushokresult(keypad(w, bf)); } /*** Force 8-bit (or 7-bit) input characters for the window. @function meta @bool on `true` to force 8-bit input characters @treturn bool `true`, if successful @see meta(3x) */ static int Wmeta(lua_State *L) { WINDOW *w = checkwin(L, 1); int bf = lua_toboolean(L, 2); return pushokresult(meta(w, bf)); } /*** Force @{getch} to be non-blocking. @function nodelay @bool on @treturn bool `true`, if successful @see nodelay(3x) */ static int Wnodelay(lua_State *L) { WINDOW *w = checkwin(L, 1); int bf = lua_toboolean(L, 2); return pushokresult(nodelay(w, bf)); } /*** For differentiating user input from terminal control sequences. @function timeout @int delay milliseconds, `0` for blocking, `-1` for non-blocking @see wtimeout(3x) */ static int Wtimeout(lua_State *L) { WINDOW *w = checkwin(L, 1); int delay = checkint(L, 2); wtimeout(w, delay); return 0; } /*** Return input immediately from this window. @function notimeout @bool bf @treturn bool `true`, if successful @fixme ncurses only? */ static int Wnotimeout(lua_State *L) { WINDOW *w = checkwin(L, 1); int bf = lua_toboolean(L, 2); return pushokresult(notimeout(w, bf)); } /*** The next call to @{refresh} will clear and completely redraw the window. @function clearok @bool bf @treturn bool `true`, if successful @see clearok(3x) */ static int Wclearok(lua_State *L) { WINDOW *w = checkwin(L, 1); int bf = lua_toboolean(L, 2); return pushokresult(clearok(w, bf)); } /*** Use hardware character insert and delete on supporting terminals. @function idcok @bool bf @treturn bool `true`, if successful @see idcok(3x) */ static int Widcok(lua_State *L) { WINDOW *w = checkwin(L, 1); int bf = lua_toboolean(L, 2); idcok(w, bf); return 0; } /*** Use hardware line insert and delete on supporting terminals. @function idlok @bool bf @treturn bool `true`, if successful @see idlok(3x) */ static int Widlok(lua_State *L) { WINDOW *w = checkwin(L, 1); int bf = lua_toboolean(L, 2); return pushokresult(idlok(w, bf)); } /*** No need to force synchronisation of hardware cursor. @function leaveok @bool bf @treturn bool `true`, if successful @see leaveok(3x) */ static int Wleaveok(lua_State *L) { WINDOW *w = checkwin(L, 1); int bf = lua_toboolean(L, 2); return pushokresult(leaveok(w, bf)); } /*** Scroll up one line when the cursor writes to the last screen position. @function scrollok @bool bf @treturn bool `true`, if successful @see scrollok(3x) */ static int Wscrollok(lua_State *L) { WINDOW *w = checkwin(L, 1); int bf = lua_toboolean(L, 2); return pushokresult(scrollok(w, bf)); } /*** Automatically call @{refresh} whenever the window content is changed. @function immedok @bool bf @treturn bool `true`, if successful @see immedok(3x) */ static int Wimmedok(lua_State *L) { WINDOW *w = checkwin(L, 1); #if LCURSES_POSIX_COMPLIANT int bf = lua_toboolean(L, 2); immedok(w, bf); return 0; #else return binding_notimplemented(L, "immedok", "curses"); #endif } /*** Set a software scrolling region for the window. @function wsetscrreg @int top top line of the scrolling region (line 0 is the first line) @int bot bottom line of the scrolling region @treturn bool `true`, if successful @see wsetscrreg(3x) */ static int Wwsetscrreg(lua_State *L) { WINDOW *w = checkwin(L, 1); int top = checkint(L, 2); int bot = checkint(L, 3); return pushokresult(wsetscrreg(w, top, bot)); } /*** Overlay this window on top of another non-destructively. @function overlay @tparam window dst destination window @treturn bool `true`, if successful @see overlay(3x) @see overwrite */ static int Woverlay(lua_State *L) { WINDOW *srcwin = checkwin(L, 1); WINDOW *dstwin = checkwin(L, 2); return pushokresult(overlay(srcwin, dstwin)); } /*** Destructively overwrite another window with this one. @function overwrite @tparam window dst destination window @treturn bool `true`, if successful @see overwrite(3x) */ static int Woverwrite(lua_State *L) { WINDOW *srcwin = checkwin(L, 1); WINDOW *dstwin = checkwin(L, 2); return pushokresult(overwrite(srcwin, dstwin)); } /*** Overlay a rectangle of this window over another. @function copywin @tparam window dst destination window @int st top row from this window @int sl left column from this window @int dt top row of rectangle @int dl left column of rectangle @int db bottom row of rectangle @int dr right column of rectangle @bool overlay if `true`, copy destructively like @{overlay} @treturn bool `true`, if successful @see copywin(3x) */ static int Wcopywin(lua_State *L) { WINDOW *srcwin = checkwin(L, 1); WINDOW *dstwin = checkwin(L, 2); int sminrow = checkint(L, 3); int smincol = checkint(L, 4); int dminrow = checkint(L, 5); int dmincol = checkint(L, 6); int dmaxrow = checkint(L, 7); int dmaxcol = checkint(L, 8); int woverlay = lua_toboolean(L, 9); return pushokresult(copywin(srcwin, dstwin, sminrow, smincol, dminrow, dmincol, dmaxrow, dmaxcol, woverlay)); } /*** Delete the character under the cursor. @function delch @treturn bool `true`, if successful @see wdelch(3x) */ static int Wdelch(lua_State *L) { return pushokresult(wdelch(checkwin(L, 1))); } /*** Call @{move} then @{delch}. @function mvdelch @int y @int x @treturn bool `true`, if successful @see mvwdelch(3x) */ static int Wmvdelch(lua_State *L) { WINDOW *w = checkwin(L, 1); int y = checkint(L, 2); int x = checkint(L, 3); return pushokresult(mvwdelch(w, y, x)); } /*** Move the lines below the cursor up, to delete the current line. @function deleteln @treturn bool `true`, if successful @see wdeleteln(3x) */ static int Wdeleteln(lua_State *L) { return pushokresult(wdeleteln(checkwin(L, 1))); } /*** Move the current line and those below down one line, leaving a new blank line. @function insertln @treturn bool `true`, if successful @see wdeleteln(3x) */ static int Winsertln(lua_State *L) { return pushokresult(winsertln(checkwin(L, 1))); } /*** Call @{deleteln} *n* times. @function winsdelln @int n @treturn bool `true`, if successful @see winsdelln(3x) */ static int Wwinsdelln(lua_State *L) { WINDOW *w = checkwin(L, 1); int n = checkint(L, 2); return pushokresult(winsdelln(w, n)); } /*** Read a character from the window input. @function getch @treturn int character read from input buffer @see wgetch(3x) @see curses.cbreak @see curses.echo @see keypad */ extern void developer_mode (lua_State *L, const char *status_message); static int Wgetch(lua_State *L) { WINDOW *w = checkwin(L, 1); int y, x; getyx(w, y, x); render_trusted_teliva_data(L); /* Apps can draw what they want on screen, * but Teliva's UI is always visible when * asking the user to make a decision. */ mvaddstr(y, x, ""); int c = wgetch(w); if (c == ERR) return 0; if (c == CTRL_X) { unlink("teliva_editor_state"); exit(0); } if (c == CTRL_E) developer_mode(L, /*status message*/ ""); /* handle other standard menu hotkeys here */ return pushintresult(c); } /*** Call @{move} then @{getch} @function mvgetch @int y @int x @treturn int character read from inpu
# dwm - dynamic window manager
# © 2006-2007 Anselm R. Garbe, Sander van Dijk

include config.mk

SRC = client.c draw.c event.c layout.c main.c tag.c util.c
OBJ = ${SRC:.c=.o}

all: options dwm

options:
	@echo dwm build options:
	@echo "CFLAGS   = ${CFLAGS}"
	@echo "LDFLAGS  = ${LDFLAGS}"
	@echo "CC       = ${CC}"

.c.o:
	@echo CC $<
	@${CC} -c ${CFLAGS} $<

${OBJ}: dwm.h config.h config.mk

config.h:
	@echo creating $@ from config.default.h
	@cp config.default.h $@

dwm: ${OBJ}
	@echo CC -o $@
	@${CC} -o $@ ${OBJ} ${LDFLAGS}
	@strip $@

clean:
	@echo cleaning
	@rm -f dwm ${OBJ} dwm-${VERSION}.tar.gz

dist: clean
	@echo creating dist tarball
	@mkdir -p dwm-${VERSION}
	@cp -R LICENSE Makefile README config.*.h config.mk \
		dwm.1 dwm.h ${SRC} dwm-${VERSION}
	@tar -cf dwm-${VERSION}.tar dwm-${VERSION}
	@gzip dwm-${VERSION}.tar
	@rm -rf dwm-${VERSION}

install: all
	@echo installing executable file to ${DESTDIR}${PREFIX}/bin
	@mkdir -p ${DESTDIR}${PREFIX}/bin
	@cp -f dwm ${DESTDIR}${PREFIX}/bin
	@chmod 755 ${DESTDIR}${PREFIX}/bin/dwm
	@echo installing manual page to ${DESTDIR}${MANPREFIX}/man1
	@mkdir -p ${DESTDIR}${MANPREFIX}/man1
	@sed