├── .github └── workflows │ ├── c.yml │ └── coverity.yml ├── .hgignore ├── .hgsigs ├── DISTRIBUTORS ├── FAQ ├── LICENSE ├── Makefile ├── NEWS ├── PKGBUILD ├── README.md ├── TODO ├── alternative_wmiircs ├── Makefile ├── README ├── plan9port │ ├── Makefile │ ├── README │ └── wmiirc ├── python │ ├── Makefile │ ├── README │ ├── pygmi.py │ ├── pygmi │ │ ├── __init__.py │ │ ├── event.py │ │ ├── fs.py │ │ ├── menu.py │ │ ├── monitor.py │ │ └── util.py │ ├── pyxp.py │ ├── pyxp │ │ ├── __init__.py │ │ ├── asyncclient.py │ │ ├── client.py │ │ ├── dial.py │ │ ├── fcall.py │ │ ├── fields.py │ │ ├── messages.py │ │ ├── mux.py │ │ └── types.py │ ├── wmiirc │ └── wmiirc.py └── ruby │ ├── HISTORY │ ├── LICENSE │ ├── Makefile │ ├── README │ ├── config.rb │ ├── config.yaml │ └── wmiirc ├── cmd ├── Makefile ├── menu │ ├── Makefile │ ├── caret.c │ ├── dat.h │ ├── fns.h │ ├── history.c │ ├── keys.c │ ├── keys.txt │ ├── main.c │ └── menu.c ├── strut │ ├── Makefile │ ├── dat.h │ ├── ewmh.c │ ├── fns.h │ ├── main.c │ └── win.c ├── tray │ ├── Makefile │ ├── client.c │ ├── dat.h │ ├── ewmh.c │ ├── fns.h │ ├── main.c │ ├── selection.c │ ├── selection.h │ ├── tray.c │ └── xembed.c ├── wihack.sh ├── wmii.rc.rc ├── wmii.sh.sh ├── wmii │ ├── Makefile │ ├── area.c │ ├── backtrace.c │ ├── bar.c │ ├── client.c │ ├── column.c │ ├── dat.h │ ├── debug.h │ ├── div.c │ ├── error.c │ ├── event.c │ ├── ewmh.c │ ├── float.c │ ├── fns.h │ ├── frame.c │ ├── fs.c │ ├── key.c │ ├── layout.c │ ├── main.c │ ├── message.c │ ├── mouse.c │ ├── print.c │ ├── root.c │ ├── rule.c │ ├── screen.c │ ├── stack.c │ ├── utf.c │ ├── view.c │ └── xdnd.c ├── wmiir.c └── x11 │ ├── Makefile │ ├── setfocus.c │ ├── wikeyname.c │ ├── wiwarp.c │ └── wmii9menu.c ├── config.mk ├── debian ├── changelog ├── compat ├── control ├── copyright ├── docs ├── file │ └── wmii.desktop ├── rules ├── wmii.menu └── wmii.wm ├── doc ├── Makefile ├── customizing.tex ├── floating.png ├── focused.png ├── gettingstarted.tex ├── introduction.tex ├── license.tex ├── managed.png ├── mkfile ├── selected.png ├── unfocused.png ├── unselected.png ├── wmii.pdf └── wmii.tex ├── examples ├── Makefile └── wimenu-file-completion.sh ├── img ├── icon.png ├── mkfile ├── wmii.eps ├── wmii.mp ├── wmii.pdf └── wmii.png ├── include ├── Makefile ├── bio.h ├── fmt.h ├── plan9.h ├── regcomp.h ├── regexp9.h ├── stuff │ ├── base.h │ ├── clientutil.h │ ├── geom.h │ ├── util.h │ ├── x.h │ └── x11.h └── utf.h ├── lib ├── Makefile ├── libbio │ ├── Makefile │ ├── NOTICE │ ├── README │ ├── bbuffered.c │ ├── bcat.c │ ├── bfildes.c │ ├── bflush.c │ ├── bgetc.c │ ├── bgetd.c │ ├── bgetrune.c │ ├── binit.c │ ├── bio.3 │ ├── boffset.c │ ├── bprint.c │ ├── bputc.c │ ├── bputrune.c │ ├── brdline.c │ ├── brdstr.c │ ├── bread.c │ ├── bseek.c │ ├── bvprint.c │ └── bwrite.c ├── libfmt │ ├── Makefile │ ├── NOTICE │ ├── README │ ├── charstod.c │ ├── dofmt.c │ ├── dorfmt.c │ ├── errfmt.c │ ├── fltfmt.c │ ├── fmt.c │ ├── fmtdef.h │ ├── fmtfd.c │ ├── fmtfdflush.c │ ├── fmtinstall.3 │ ├── fmtlocale.c │ ├── fmtlock.c │ ├── fmtprint.c │ ├── fmtquote.c │ ├── fmtrune.c │ ├── fmtstr.c │ ├── fmtvprint.c │ ├── fprint.c │ ├── libfmt.a │ ├── nan64.c │ ├── pow10.c │ ├── print.3 │ ├── print.c │ ├── runefmtstr.c │ ├── runeseprint.c │ ├── runesmprint.c │ ├── runesnprint.c │ ├── runesprint.c │ ├── runevseprint.c │ ├── runevsmprint.c │ ├── runevsnprint.c │ ├── seprint.c │ ├── smprint.c │ ├── snprint.c │ ├── sprint.c │ ├── strtod.c │ ├── test.c │ ├── test2.c │ ├── test3.c │ ├── vfprint.c │ ├── vseprint.c │ ├── vsmprint.c │ └── vsnprint.c ├── libregexp │ ├── Makefile │ ├── NOTICE │ ├── README │ ├── regaux.c │ ├── regcomp.c │ ├── regerror.c │ ├── regexec.c │ ├── regexp9.3 │ ├── regexp9.7 │ ├── regsub.c │ ├── rregexec.c │ ├── rregsub.c │ ├── test.c │ └── test2.c ├── libstuff │ ├── Makefile │ ├── buffer.c │ ├── client_readconfig.c │ ├── clientutil.c │ ├── event │ │ ├── buttonpress.c │ │ ├── buttonrelease.c │ │ ├── clientmessage.c │ │ ├── configurenotify.c │ │ ├── configurerequest.c │ │ ├── destroynotify.c │ │ ├── enternotify.c │ │ ├── event.c │ │ ├── event.h │ │ ├── expose.c │ │ ├── focusin.c │ │ ├── focusout.c │ │ ├── ixp.c │ │ ├── keypress.c │ │ ├── keyrelease.c │ │ ├── leavenotify.c │ │ ├── mapnotify.c │ │ ├── mappingnotify.c │ │ ├── maprequest.c │ │ ├── motionnotify.c │ │ ├── propertynotify.c │ │ ├── reparentnotify.c │ │ ├── selection.c │ │ ├── selectionclear.c │ │ ├── selectionrequest.c │ │ ├── unmapnotify.c │ │ └── xtime.c │ ├── fmt │ │ ├── blprint.c │ │ ├── bvlprint.c │ │ ├── fmtbuf.c │ │ ├── fmtdef.h │ │ ├── localefmt.c │ │ ├── localelen.c │ │ ├── lprint.c │ │ └── vlprint.c │ ├── geom │ │ ├── get_sticky.c │ │ ├── quadrant.c │ │ ├── rect_contains_p.c │ │ ├── rect_haspoint_p.c │ │ ├── rect_intersect_p.c │ │ └── rect_intersection.c │ ├── init_screens.c │ ├── map.c │ ├── printevent.c │ ├── printevent.h │ ├── util │ │ ├── _die.c │ │ ├── closeexec.c │ │ ├── comm.c │ │ ├── doublefork.c │ │ ├── emalloc.c │ │ ├── emallocz.c │ │ ├── erealloc.c │ │ ├── estrdup.c │ │ ├── estrndup.c │ │ ├── fatal.c │ │ ├── freelater.c │ │ ├── getbase.c │ │ ├── getint.c │ │ ├── getlong.c │ │ ├── getulong.c │ │ ├── grep.c │ │ ├── join.c │ │ ├── max.c │ │ ├── mfatal.c │ │ ├── min.c │ │ ├── nsec.c │ │ ├── pathsearch.c │ │ ├── refree.c │ │ ├── reinit.c │ │ ├── spawn3.c │ │ ├── spawn3l.c │ │ ├── stokenize.c │ │ ├── strcasestr.c │ │ ├── strend.c │ │ ├── strlcat.c │ │ ├── strlcatprint.c │ │ ├── sxprint.c │ │ ├── tokenize.c │ │ ├── trim.c │ │ ├── uniq.c │ │ ├── unmask.c │ │ ├── unquote.c │ │ ├── utflcpy.c │ │ ├── util.h │ │ ├── vector.c │ │ └── vsxprint.c │ ├── x11 │ │ ├── colors │ │ │ ├── loadcolor.c │ │ │ ├── parsecolor.c │ │ │ └── xftcolor.c │ │ ├── convpts.c │ │ ├── drawing │ │ │ ├── border.c │ │ │ ├── drawline.c │ │ │ ├── drawpoly.c │ │ │ ├── drawstring.c │ │ │ ├── fill.c │ │ │ ├── fillpoly.c │ │ │ └── setgccol.c │ │ ├── errors.c │ │ ├── focus │ │ │ ├── getfocus.c │ │ │ └── setfocus.c │ │ ├── freestringlist.c │ │ ├── geometry │ │ │ ├── XRect.c │ │ │ ├── addpt.c │ │ │ ├── divpt.c │ │ │ ├── eqpt.c │ │ │ ├── eqrect.c │ │ │ ├── insetrect.c │ │ │ ├── mulpt.c │ │ │ ├── rectaddpt.c │ │ │ ├── rectsetorigin.c │ │ │ ├── rectsubpt.c │ │ │ └── subpt.c │ │ ├── ignored_xerrors.c │ │ ├── images │ │ │ ├── allocimage.c │ │ │ ├── copyimage.c │ │ │ ├── freeimage.c │ │ │ └── xftdrawable.c │ │ ├── initdisplay.c │ │ ├── insanity │ │ │ ├── gethints.c │ │ │ ├── gravitate.c │ │ │ ├── sethints.c │ │ │ └── sizehint.c │ │ ├── keyboard │ │ │ ├── grabkeyboard.c │ │ │ └── ungrabkeyboard.c │ │ ├── keys │ │ │ ├── keycode.c │ │ │ └── parsekey.c │ │ ├── mouse │ │ │ ├── grabpointer.c │ │ │ ├── pointerscreen.c │ │ │ ├── querypointer.c │ │ │ ├── translate.c │ │ │ ├── ungrabpointer.c │ │ │ └── warppointer.c │ │ ├── properties │ │ │ ├── changeprop_char.c │ │ │ ├── changeprop_long.c │ │ │ ├── changeprop_short.c │ │ │ ├── changeprop_string.c │ │ │ ├── changeprop_textlist.c │ │ │ ├── changeprop_ulong.c │ │ │ ├── changeproperty.c │ │ │ ├── delproperty.c │ │ │ ├── getprop.c │ │ │ ├── getprop_long.c │ │ │ ├── getprop_string.c │ │ │ ├── getprop_textlist.c │ │ │ ├── getproperty.c │ │ │ ├── strlistdup.c │ │ │ └── windowname.c │ │ ├── selection.c │ │ ├── sendevent.c │ │ ├── sendmessage.c │ │ ├── shape │ │ │ └── setshapemask.c │ │ ├── sync.c │ │ ├── text │ │ │ ├── freefont.c │ │ │ ├── labelh.c │ │ │ ├── loadfont.c │ │ │ ├── textextents_l.c │ │ │ ├── textwidth.c │ │ │ └── textwidth_l.c │ │ ├── windows │ │ │ ├── configwin.c │ │ │ ├── createwindow.c │ │ │ ├── createwindow_rgba.c │ │ │ ├── createwindow_visual.c │ │ │ ├── destroywindow.c │ │ │ ├── findwin.c │ │ │ ├── getwinrect.c │ │ │ ├── lowerwin.c │ │ │ ├── mapwin.c │ │ │ ├── movewin.c │ │ │ ├── raisewin.c │ │ │ ├── reparentwindow.c │ │ │ ├── reshapewin.c │ │ │ ├── selectinput.c │ │ │ ├── setborder.c │ │ │ ├── sethandler.c │ │ │ ├── setwinattr.c │ │ │ ├── unmapwin.c │ │ │ └── window.c │ │ ├── x11.c │ │ ├── x11.h │ │ ├── xatom.c │ │ └── xft.c │ └── xext.c ├── libutf │ ├── Makefile │ ├── NOTICE │ ├── README │ ├── isalpharune.3 │ ├── libutf.a │ ├── rune.3 │ ├── rune.c │ ├── runestrcat.3 │ ├── runestrcat.c │ ├── runestrchr.c │ ├── runestrcmp.c │ ├── runestrcpy.c │ ├── runestrdup.c │ ├── runestrecpy.c │ ├── runestrlen.c │ ├── runestrncat.c │ ├── runestrncmp.c │ ├── runestrncpy.c │ ├── runestrrchr.c │ ├── runestrstr.c │ ├── runetype.c │ ├── utf.7 │ ├── utfecpy.c │ ├── utflen.c │ ├── utfnlen.c │ ├── utfrrune.c │ ├── utfrune.c │ └── utfutf.c └── libwmii_hack │ ├── Makefile │ ├── hack.c │ ├── hack.h │ ├── util.c │ ├── x11.c │ └── x11.h ├── man ├── Makefile ├── header.t2t ├── mkfile ├── wihack.1 ├── wihack.man1 ├── wimenu.1 ├── wimenu.man1 ├── wistrut.1 ├── wistrut.man1 ├── witray.1 ├── witray.man1 ├── wmii.1 ├── wmii.man1 ├── wmii9menu.1 ├── wmii9menu.man1 ├── wmiir.1 └── wmiir.man1 ├── mk ├── common.mk ├── dir.mk ├── gcc.mk ├── hdr.mk ├── lib.mk ├── man.mk ├── many.mk ├── one.mk ├── python.mk ├── so.mk └── wmii.mk ├── rc ├── Makefile ├── sh.wmii ├── welcome.sh └── wmiirc.sh ├── test ├── Makefile ├── event ├── event.b ├── grav.c └── mkfile └── util ├── cleanname ├── compile ├── genchangelog ├── genconfig └── link /.github/workflows/c.yml: -------------------------------------------------------------------------------- 1 | name: C 2 | 3 | on: 4 | push: 5 | branches: [ main ] 6 | pull_request: 7 | branches: [ main ] 8 | 9 | jobs: 10 | build: 11 | 12 | runs-on: ubuntu-latest 13 | 14 | steps: 15 | - uses: actions/checkout@v3 16 | 17 | - name: Checkout libixp 18 | uses: actions/checkout@v3 19 | with: 20 | repository: 0intro/libixp 21 | path: libixp 22 | 23 | - name: Dependencies 24 | run: sudo apt-get -y install libxinerama-dev libxrandr-dev txt2tags 25 | 26 | - name: Build libixp 27 | working-directory: ./libixp 28 | run: sudo make install 29 | 30 | - name: make clean 31 | run: make clean 32 | 33 | - name: make 34 | run: make 35 | -------------------------------------------------------------------------------- /.github/workflows/coverity.yml: -------------------------------------------------------------------------------- 1 | name: Coverity Scan 2 | 3 | on: 4 | push: 5 | branches: [ main ] 6 | 7 | jobs: 8 | coverity: 9 | runs-on: ubuntu-latest 10 | steps: 11 | - uses: actions/checkout@v3 12 | 13 | - name: Checkout libixp 14 | uses: actions/checkout@v3 15 | with: 16 | repository: 0intro/libixp 17 | path: libixp 18 | 19 | - name: Build libixp 20 | working-directory: ./libixp 21 | run: sudo make install 22 | 23 | - name: Dependencies 24 | run: sudo apt-get -y install libxinerama-dev libxrandr-dev txt2tags 25 | 26 | - uses: vapier/coverity-scan-action@v1 27 | with: 28 | email: ${{ secrets.COVERITY_SCAN_EMAIL }} 29 | token: ${{ secrets.COVERITY_SCAN_TOKEN }} 30 | -------------------------------------------------------------------------------- /.hgignore: -------------------------------------------------------------------------------- 1 | syntax: regexp 2 | (^|/)\.((.*\.)?sw.|depend|hgignore)$ 3 | (^|/)(tags|mkfile|diff)$ 4 | \.([oa]|out|o_pic|so|pyc|pyo|diff)$ 5 | \.(diff|orig|rej|bak)$ 6 | \.(aux|idx|ilg|ind|log|toc)$ 7 | ^cmd/osd(/|$) 8 | ^cmd/x11/(stfo|wiclick)\. 9 | ^(pkg|src)/ 10 | ^doxy 11 | /bak/ 12 | _dummy\.h$ 13 | syntax: glob 14 | config.local.mk 15 | cmd/menu/bindings.c 16 | *.pkg.tar.?z 17 | alternative_wmiircs/python/build/ 18 | alternative_wmiircs/python/dist/ 19 | -------------------------------------------------------------------------------- /.hgsigs: -------------------------------------------------------------------------------- 1 | 3b3ace9543175ecba98e5b3245ec39b103edc33b 0 iD8DBQBGXiI6seQZD8Aui4wRAmhLAJ4wf+TzWEk431kNN3CONMTVGK61YgCfVDWsjKlQDym+s30UMeE38hr9vv8= 2 | 3ea520ff8668c297a5c6b667a68b3c3a1f44fec5 0 iD8DBQBGXiNCseQZD8Aui4wRAlAfAJ9jGmSOX0nZ9J8vnpnWj2bCb9/GngCfTCIKWJfcyHsmXBxniuys14ncRn8= 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Copyright © 2006-2010 Kris Maglione 3 | Copyright © 2003-2006 Anselm R Garbe 4 | Portions Copyright © 2002 by Lucent Technologies. 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the "Software"), 8 | to deal in the Software without restriction, including without limitation 9 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | and/or sell copies of the Software, and to permit persons to whom the 11 | Software is furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 | DEALINGS IN THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | ROOT=. 2 | include $(ROOT)/mk/hdr.mk 3 | include $(ROOT)/mk/wmii.mk 4 | 5 | DIRS = \ 6 | doc \ 7 | examples \ 8 | man \ 9 | lib \ 10 | cmd \ 11 | rc \ 12 | alternative_wmiircs 13 | 14 | DOCS = FAQ \ 15 | LICENSE \ 16 | README.md 17 | 18 | deb-dep: 19 | IFS=', '; \ 20 | apt-get -qq install build-essential $$(sed -n 's/([^)]*)//; s/^Build-Depends: \(.*\)/\1/p' debian/control) 21 | 22 | DISTRO = unstable 23 | deb: 24 | $(ROOT)/util/genchangelog wmii-hg $(VERSION) $(DISTRO) 25 | dpkg-buildpackage -rfakeroot -b -nc 26 | [ -d .hg ] && hg revert debian/changelog || true 27 | 28 | include $(ROOT)/mk/dir.mk 29 | 30 | -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | BUGS 2 | * collapsed clients outside stacked mode don't always uncollapse when they receive focus 3 | * various qiv brokenness 4 | * dosbox won't grab the mouse 5 | 6 | 4.0 7 | * Opaque managed moves. I know I've argued against it, but it may be doable. 8 | * Clicking layout boxes should do useful things. 9 | * Collapse/uncollapse frames with the keyboard. 10 | * Open modes (to replace colmodes). 11 | * Resizable managed area. Maybe. Struts seem to do everything this might. 12 | * New dmenu, with real cursor; snarfable. 13 | 14 | -------------------------------------------------------------------------------- /alternative_wmiircs/Makefile: -------------------------------------------------------------------------------- 1 | ROOT=.. 2 | include $(ROOT)/mk/hdr.mk 3 | include $(ROOT)/mk/wmii.mk 4 | 5 | BIN = $(GLOBALCONF) 6 | DIRS = python \ 7 | plan9port \ 8 | ruby 9 | 10 | DOCS = README 11 | DOCDIR = $(DOC)/alternative_wmiircs 12 | 13 | include $(ROOT)/mk/dir.mk 14 | -------------------------------------------------------------------------------- /alternative_wmiircs/README: -------------------------------------------------------------------------------- 1 | Alternative wmiirc scripts 2 | ========================== 3 | 4 | This folder contains alternative implementations of wmii's rc 5 | scripts. Each folder contains a different implementation, 6 | described below, including its own README, wmiirc script, and 7 | possibly other suppporting files and libraries. These scripts 8 | are installed along with wmii to $(ETC) as defined in config.mk. 9 | 10 | It usually suffices to start the included `wmiirc` script at 11 | wmii startup. Invoking wmii with the flag '-r python/wmiirc', 12 | for instance, will start the python implementation. 13 | Alternatively, if you use a session manager, you can add this 14 | line to @LOCALCONF@/wmiirc (which must be executable): 15 | 16 | wmiir xwrite /ctl spawn python/wmiirc 17 | 18 | Index 19 | ------------- ---------------------------------------------------- 20 | python/ A pure Python wmiirc implementation. 21 | plan9port/ A Plan 9 Port/rc shell based wmiirc implementation 22 | ruby/ A pure-ruby wmiirc implementation, by Suraj Kurapati 23 | 24 | -------------------------------------------------------------------------------- /alternative_wmiircs/plan9port/Makefile: -------------------------------------------------------------------------------- 1 | ROOT=../.. 2 | include $(ROOT)/mk/hdr.mk 3 | include $(ROOT)/mk/wmii.mk 4 | 5 | DOCS = README 6 | EXECS = wmiirc 7 | 8 | DIR = $(GLOBALCONF)/plan9port 9 | DOCDIR = $(DOC)/alternative_wmiircs/plan9port 10 | -------------------------------------------------------------------------------- /alternative_wmiircs/plan9port/README: -------------------------------------------------------------------------------- 1 | plan9port wmiirc 2 | ================ 3 | 4 | This directory contains a Plan 9 based wmiirc script. This script was 5 | traditionally the default wmiirc for wmii, but has been moved for 6 | portability reasons. To run this script, either Plan 9 from User 7 | Space[1] (plan9port for short) or 9base[2] is required. Modifications 8 | can be placed in @LOCALCONF@/wmiirc_local.rc, which must 9 | be executable. 10 | 11 | -------------------------------------------------------------------------------- /alternative_wmiircs/python/Makefile: -------------------------------------------------------------------------------- 1 | ROOT=../.. 2 | include $(ROOT)/mk/hdr.mk 3 | include $(ROOT)/mk/wmii.mk 4 | 5 | PYMODULES = pyxp pygmi 6 | 7 | DOCS = README 8 | EXECS = wmiirc 9 | TEXT = wmiirc.py 10 | 11 | DIR = $(GLOBALCONF)/python 12 | DOCDIR = $(DOC)/alternative_wmiircs/python 13 | 14 | include $(ROOT)/mk/python.mk 15 | -------------------------------------------------------------------------------- /alternative_wmiircs/python/README: -------------------------------------------------------------------------------- 1 | Python wmiirc 2 | ============= 3 | 4 | This directory contains a pure Python implementation of 5 | wmiirc. The two included libraries, pyxp and pygmi, are a 9P 6 | client and wmii filesystem utility module, respectively. To 7 | use this library, simply copy the contents of this direcctory 8 | to @LOCALCONF@. To customize it, either modify wmiirc.py 9 | directly, or create wmii_local.py and store your modifications 10 | there. The latter approach is preferable in that future 11 | modifications to wmiirc.py can usually be painlessly 12 | integrated. 13 | 14 | The documentation is sparse, but wmiirc.py should serve as a 15 | fairly comprehensive example. 16 | 17 | -------------------------------------------------------------------------------- /alternative_wmiircs/python/pygmi.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | from distutils.core import setup 4 | 5 | setup(name='pygmi', 6 | version='0.2', 7 | description='Python wmii interaction library', 8 | author='Kris Maglione', 9 | author_email='maglione.k@gmail.com', 10 | url='http://wmii.suckless.org', 11 | packages=['pygmi'], 12 | license='MIT', 13 | ) 14 | 15 | -------------------------------------------------------------------------------- /alternative_wmiircs/python/pygmi/__init__.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | 4 | from pyxp.asyncclient import Client 5 | 6 | if 'WMII_ADDRESS' in os.environ: 7 | client = Client(os.environ['WMII_ADDRESS']) 8 | else: 9 | client = Client(namespace='wmii') 10 | 11 | confpath = os.environ.get('WMII_CONFPATH', '%s/.wmii' % os.environ['HOME']).split(':') 12 | shell = os.environ['SHELL'] 13 | 14 | sys.path += confpath 15 | 16 | from pygmi.util import * 17 | from pygmi.event import * 18 | from pygmi.fs import * 19 | from pygmi.menu import * 20 | from pygmi.monitor import * 21 | from pygmi import util, event, fs, menu, monitor 22 | 23 | __all__ = (fs.__all__ + monitor.__all__ + event.__all__ + 24 | menu.__all__ + util.__all__ + 25 | ('client', 'confpath', 'shell')) 26 | 27 | # vim:se sts=4 sw=4 et: 28 | -------------------------------------------------------------------------------- /alternative_wmiircs/python/pyxp.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | from distutils.core import setup 4 | 5 | setup(name='pyxp', 6 | version='0.2', 7 | description='Python 9P client library', 8 | author='Kris Maglione', 9 | author_email='maglione.k@gmail.com', 10 | url='http://wmii.suckless.org', 11 | packages=['pyxp'], 12 | license='MIT', 13 | ) 14 | 15 | -------------------------------------------------------------------------------- /alternative_wmiircs/python/pyxp/__init__.py: -------------------------------------------------------------------------------- 1 | from pyxp.client import Client 2 | from pyxp.dial import dial 3 | from pyxp.types import Qid, Stat 4 | 5 | VERSION = '9P2000' 6 | 7 | # vim:se sts=4 sw=4 et: 8 | -------------------------------------------------------------------------------- /alternative_wmiircs/python/pyxp/dial.py: -------------------------------------------------------------------------------- 1 | from socket import * 2 | 3 | __all__ = 'dial', 4 | 5 | def dial_unix(address): 6 | sock = socket(AF_UNIX, SOCK_STREAM, 0) 7 | sock.connect(address) 8 | return sock 9 | 10 | def dial_tcp(host): 11 | host = host.split('!') 12 | if len(host) != 2: 13 | return 14 | host, port = host 15 | 16 | res = getaddrinfo(host, port, AF_INET, SOCK_STREAM, 0, AI_PASSIVE) 17 | for family, socktype, protocol, name, addr in res: 18 | try: 19 | sock = socket(family, socktype, protocol) 20 | sock.connect(addr) 21 | return sock 22 | except error: 23 | if sock: 24 | sock.close() 25 | 26 | def dial(address): 27 | proto, address = address.split('!', 1) 28 | if proto == 'unix': 29 | return dial_unix(address) 30 | elif proto == 'tcp': 31 | return dial_tcp(address) 32 | else: 33 | raise Exception('invalid protocol') 34 | 35 | # vim:se sts=4 sw=4 et: 36 | -------------------------------------------------------------------------------- /alternative_wmiircs/python/wmiirc: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env @PYTHON@ 2 | import os, sys 3 | path = [] 4 | for p in os.environ.get("WMII_CONFPATH", "").split(':'): 5 | path += [p, p + '/python'] 6 | sys.path = path + sys.path 7 | 8 | from pygmi import events 9 | import wmiirc 10 | 11 | events.loop() 12 | 13 | -------------------------------------------------------------------------------- /alternative_wmiircs/ruby/LICENSE: -------------------------------------------------------------------------------- 1 | (the ISC license) 2 | 3 | Copyright 2006 Suraj N. Kurapati 4 | Copyright 2007 Kris Maglione 5 | Copyright 2007 Nick Stenning 6 | Copyright 2009 Daniel Wäber 7 | Copyright 2009 Michael Andrus 8 | Copyright 2009 Simon Hafner 9 | 10 | Permission to use, copy, modify, and distribute this software for any 11 | purpose with or without fee is hereby granted, provided that the above 12 | copyright notice and this permission notice appear in all copies. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 15 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 16 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 17 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 18 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 19 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 20 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 21 | 22 | -------------------------------------------------------------------------------- /alternative_wmiircs/ruby/Makefile: -------------------------------------------------------------------------------- 1 | ROOT=../.. 2 | include $(ROOT)/mk/hdr.mk 3 | include $(ROOT)/mk/wmii.mk 4 | 5 | DOCS = README \ 6 | HISTORY \ 7 | LICENSE 8 | EXECS = wmiirc 9 | TEXT = config.rb \ 10 | config.yaml 11 | 12 | DIR = $(GLOBALCONF)/ruby 13 | DOCDIR = $(DOC)/alternative_wmiircs/ruby 14 | -------------------------------------------------------------------------------- /cmd/Makefile: -------------------------------------------------------------------------------- 1 | ROOT=.. 2 | include $(ROOT)/mk/hdr.mk 3 | include $(ROOT)/mk/wmii.mk 4 | 5 | wmiir.c: $(ROOT)/mk/wmii.mk 6 | 7 | DIRS = menu \ 8 | strut \ 9 | tray \ 10 | wmii \ 11 | x11 12 | TARG = wihack \ 13 | wmii.rc \ 14 | wmii.sh \ 15 | wmiir 16 | 17 | LIBS += $(LIBS9) $(LIBIXP) 18 | 19 | include $(ROOT)/mk/many.mk 20 | include $(ROOT)/mk/dir.mk 21 | 22 | -------------------------------------------------------------------------------- /cmd/menu/Makefile: -------------------------------------------------------------------------------- 1 | ROOT= ../.. 2 | include $(ROOT)/mk/hdr.mk 3 | include $(ROOT)/mk/wmii.mk 4 | 5 | main.c: $(ROOT)/mk/wmii.mk 6 | 7 | bindings.c: keys.txt Makefile 8 | ( echo "char binding_spec[] ="; \ 9 | sed 's/.*/ "&\\n"/' keys.txt; \ 10 | echo " ;" ) >$@ 11 | 12 | TARG = wimenu 13 | HFILES= dat.h fns.h 14 | TAGFILES= dat.h $(ROOT)/include/*.h $(ROOT)/include/stuff/*.h 15 | 16 | PACKAGES += $(X11PACKAGES) 17 | 18 | LIB = $(LIBS9) $(LIBIXP) 19 | LIBS += -lm 20 | OBJ = main \ 21 | caret \ 22 | history \ 23 | menu \ 24 | keys \ 25 | bindings 26 | 27 | include $(ROOT)/mk/one.mk 28 | 29 | -------------------------------------------------------------------------------- /cmd/menu/fns.h: -------------------------------------------------------------------------------- 1 | 2 | /* caret.c */ 3 | void caret_delete(int, int); 4 | char* caret_find(int, int); 5 | void caret_insert(char*, bool); 6 | void caret_move(int, int); 7 | void caret_set(int, int); 8 | 9 | /* history.c */ 10 | void history_dump(const char*, int); 11 | char* history_search(int, char*, int); 12 | 13 | /* main.c */ 14 | void debug(int, const char*, ...); 15 | Item* filter_list(Item*, char*); 16 | void update_filter(bool); 17 | void update_input(void); 18 | 19 | /* menu.c */ 20 | void menu_draw(void); 21 | void menu_init(void); 22 | void menu_show(void); 23 | 24 | /* keys.c */ 25 | void parse_keys(char*); 26 | char** find_key(char*, long); 27 | int getsym(char*); 28 | 29 | -------------------------------------------------------------------------------- /cmd/strut/Makefile: -------------------------------------------------------------------------------- 1 | ROOT= ../.. 2 | include $(ROOT)/mk/hdr.mk 3 | include $(ROOT)/mk/wmii.mk 4 | 5 | main.c: $(ROOT)/mk/wmii.mk 6 | 7 | TARG = wistrut 8 | HFILES= dat.h fns.h 9 | 10 | PACKAGES += $(X11PACKAGES) 11 | 12 | LIB = $(LIBS9) 13 | LIBS += -lm 14 | OBJ = main \ 15 | ewmh \ 16 | win 17 | 18 | include $(ROOT)/mk/one.mk 19 | 20 | -------------------------------------------------------------------------------- /cmd/strut/dat.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #ifndef EXTERN 10 | # define EXTERN extern 11 | #endif 12 | 13 | enum { DAuto, DHorizontal, DVertical }; 14 | 15 | extern Handlers handlers; 16 | EXTERN int direction; 17 | 18 | -------------------------------------------------------------------------------- /cmd/strut/fns.h: -------------------------------------------------------------------------------- 1 | 2 | void restrut(Window*); 3 | 4 | void ewmh_getstrut(Window*, Rectangle[4]); 5 | void ewmh_setstrut(Window*, Rectangle[4]); 6 | 7 | -------------------------------------------------------------------------------- /cmd/tray/Makefile: -------------------------------------------------------------------------------- 1 | ROOT= ../.. 2 | include $(ROOT)/mk/hdr.mk 3 | include $(ROOT)/mk/wmii.mk 4 | 5 | main.c: $(ROOT)/mk/wmii.mk 6 | 7 | TARG = witray 8 | HFILES= dat.h fns.h selection.h 9 | 10 | PACKAGES += $(X11PACKAGES) 11 | 12 | LIB = $(LIBS9) $(LIBIXP) 13 | LIBS += -lm 14 | OBJ = \ 15 | client \ 16 | ewmh \ 17 | main \ 18 | selection \ 19 | tray \ 20 | xembed 21 | 22 | include $(ROOT)/mk/one.mk 23 | 24 | -------------------------------------------------------------------------------- /cmd/tray/ewmh.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2007-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "dat.h" 5 | #include 6 | #include 7 | #include "fns.h" 8 | 9 | enum { 10 | Left, Right, Top, Bottom, 11 | LeftMin, LeftMax, 12 | RightMin, RightMax, 13 | TopMin, TopMax, 14 | BottomMin, BottomMax, 15 | Last 16 | }; 17 | 18 | void 19 | ewmh_setstrut(Window *w, Rectangle struts[4]) { 20 | long strut[Last]; 21 | int i; 22 | 23 | strut[LeftMin] = struts[Left].min.y; 24 | strut[Left] = struts[Left].max.x; 25 | strut[LeftMax] = struts[Left].max.y; 26 | 27 | strut[RightMin] = struts[Right].min.y; 28 | strut[Right] = -struts[Right].min.x; 29 | strut[RightMax] = struts[Right].max.y; 30 | 31 | strut[TopMin] = struts[Top].min.x; 32 | strut[Top] = struts[Top].max.y; 33 | strut[TopMax] = struts[Top].max.x; 34 | 35 | strut[BottomMin] = struts[Bottom].min.x; 36 | strut[Bottom] = -struts[Bottom].min.y; 37 | strut[BottomMax] = struts[Bottom].max.x; 38 | 39 | for(i=0; i&2 Usage: \ 6 | "$0 [-transient ] [-type [,...]] [-tags ] [ ...]" 7 | exit 1 8 | } 9 | 10 | checkarg='[ ${#@} -gt 0 ] || usage' 11 | export WMII_HACK_TIME=$(date +%s) 12 | 13 | while [ ${#@} -gt 0 ] 14 | do 15 | case $1 in 16 | -transient) 17 | shift; eval $checkarg 18 | export WMII_HACK_TRANSIENT=$1 19 | shift;; 20 | -type) 21 | shift; eval $checkarg 22 | export WMII_HACK_TYPE=$1 23 | shift;; 24 | -tags) 25 | shift; eval $checkarg 26 | export WMII_HACK_TAGS=$1 27 | shift;; 28 | -*) 29 | usage;; 30 | *) 31 | break;; 32 | esac 33 | done 34 | 35 | eval $checkarg 36 | 37 | if [ ! -u "`which $1`" -a ! -g "`which $1`" ] 38 | then 39 | export LD_PRELOAD="@LIBDIR@/libwmii_hack.so" 40 | else 41 | unset WMII_HACK_TRANSIENT WMII_HACK_TYPE WMII_HACK_TAGS 42 | fi 43 | exec "$@" 44 | 45 | -------------------------------------------------------------------------------- /cmd/wmii/Makefile: -------------------------------------------------------------------------------- 1 | ROOT= ../.. 2 | include $(ROOT)/mk/hdr.mk 3 | include $(ROOT)/mk/wmii.mk 4 | 5 | main.c: $(ROOT)/mk/wmii.mk 6 | 7 | TARG = wmii 8 | HFILES = dat.h fns.h 9 | TAGFILES = dat.h 10 | 11 | PACKAGES += $(X11PACKAGES) xext xrandr xrender xinerama 12 | 13 | LIB = $(LIBIXP) $(LIBS9) 14 | LIBS += -lm 15 | 16 | OBJ = area \ 17 | bar \ 18 | backtrace \ 19 | client \ 20 | column \ 21 | div \ 22 | error \ 23 | event \ 24 | ewmh \ 25 | float \ 26 | frame \ 27 | fs \ 28 | key \ 29 | layout \ 30 | main \ 31 | message \ 32 | mouse \ 33 | print \ 34 | root \ 35 | rule \ 36 | screen \ 37 | stack \ 38 | utf \ 39 | view \ 40 | xdnd 41 | 42 | include $(ROOT)/mk/one.mk 43 | 44 | -------------------------------------------------------------------------------- /cmd/wmii/debug.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | enum DebugOpt { 4 | D9p = 1<<0, 5 | DDnd = 1<<1, 6 | DEvent = 1<<2, 7 | DEvents = 1<<3, 8 | DEwmh = 1<<4, 9 | DFocus = 1<<5, 10 | DGeneric= 1<<6, 11 | DStack = 1<<7, 12 | NDebugOpt = 8, 13 | }; 14 | 15 | #define Debug(x) if(((debugflag|debugfile)&(x)) && setdebug(x)) 16 | #define Dprint(x, ...) BLOCK( if((debugflag|debugfile)&(x)) debug(x, __VA_ARGS__) ) 17 | 18 | void debug(int, const char*, ...); 19 | void dwrite(int, void*, int, bool); 20 | bool setdebug(int); 21 | void vdebug(int, const char*, va_list); 22 | 23 | extern long debugflag; 24 | extern long debugfile; 25 | -------------------------------------------------------------------------------- /cmd/wmii/error.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2007-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | 5 | #include "dat.h" 6 | #include "fns.h" 7 | 8 | static jmp_buf errjmp[16]; 9 | static long nerror; 10 | 11 | void 12 | error(char *fmt, ...) { 13 | char errbuf[IXP_ERRMAX]; 14 | va_list ap; 15 | 16 | va_start(ap, fmt); 17 | vsnprint(errbuf, IXP_ERRMAX, fmt, ap); 18 | va_end(ap); 19 | ixp_errstr(errbuf, IXP_ERRMAX); 20 | 21 | nexterror(); 22 | } 23 | 24 | void 25 | nexterror(void) { 26 | assert(nerror > 0); 27 | longjmp(errjmp[--nerror], 1); 28 | } 29 | 30 | void 31 | poperror(void) { 32 | assert(nerror > 0); 33 | --nerror; 34 | } 35 | 36 | jmp_buf* 37 | pusherror(void) { 38 | assert(nerror < nelem(errjmp)); 39 | return &errjmp[nerror++]; 40 | } 41 | 42 | -------------------------------------------------------------------------------- /cmd/x11/Makefile: -------------------------------------------------------------------------------- 1 | ROOT= ../.. 2 | include $(ROOT)/mk/hdr.mk 3 | include $(ROOT)/mk/wmii.mk 4 | 5 | TARG = wikeyname \ 6 | wmii9menu 7 | 8 | PACKAGES += $(X11PACKAGES) 9 | 10 | LIB = $(LIBS9) $(LIBIXP) 11 | LIBS += $(LIB) 12 | CFLAGS += $(INCX11) 13 | 14 | wiclick.out: wiclick.o 15 | $(LINK) $@ $< -lXtst 16 | 17 | include $(ROOT)/mk/many.mk 18 | 19 | -------------------------------------------------------------------------------- /cmd/x11/setfocus.c: -------------------------------------------------------------------------------- 1 | /* Copyight 2008 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | int 13 | main(int argc, char *argv[]) { 14 | XWindow w; 15 | 16 | ARGBEGIN{ 17 | }ARGEND; 18 | 19 | initdisplay(); 20 | 21 | if(!getulong(EARGF(exit(1)), &w)) 22 | exit(1); 23 | 24 | XSetInputFocus(display, w, RevertToParent, CurrentTime); 25 | XCloseDisplay(display); 26 | } 27 | 28 | -------------------------------------------------------------------------------- /cmd/x11/wiwarp.c: -------------------------------------------------------------------------------- 1 | /* Copyight 2008 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | int 13 | main(int argc, char *argv[]) { 14 | Point pt; 15 | 16 | ARGBEGIN{ 17 | }ARGEND; 18 | 19 | initdisplay(); 20 | 21 | if(argc) { 22 | if(!getint(EARGF(exit(1)), &pt.x)) 23 | exit(1); 24 | if(!getint(EARGF(exit(1)), &pt.y)) 25 | exit(1); 26 | }else { 27 | pt = querypointer(&scr.root); 28 | lprint(1, "%d %d\n", pt.x, pt.y); 29 | } 30 | 31 | warppointer(pt); 32 | XCloseDisplay(display); 33 | } 34 | 35 | -------------------------------------------------------------------------------- /debian/changelog: -------------------------------------------------------------------------------- 1 | wmii-hg (2728) unstable; urgency=low 2 | 3 | * Remove long deprecated special treatment of the '!' tag. 4 | 5 | -- Kris Maglione Tue, 15 Jun 2010 15:13:12 -0400 6 | -------------------------------------------------------------------------------- /debian/compat: -------------------------------------------------------------------------------- 1 | 7 2 | -------------------------------------------------------------------------------- /debian/control: -------------------------------------------------------------------------------- 1 | Source: wmii-hg 2 | Section: x11 3 | Priority: optional 4 | Maintainer: Kris Maglione 5 | Build-Depends: libixp-hg, dash, python, libx11-dev, libxft-dev, libxext-dev, libxinerama-dev, libxrandr-dev, x11proto-xext-dev, quilt, debhelper (>= 4.0) 6 | Standards-Version: 3.8.4 7 | Homepage: http://wmii.suckless.org/ 8 | 9 | Package: wmii-hg 10 | Architecture: any 11 | Depends: ${shlibs:Depends}, ${misc:Depends}, dash (>= 0.1) 12 | Conflicts: wmii, wmii2 13 | Replaces: wmii, wmii2 14 | Provides: x-window-manager 15 | Description: lightweight tabbed and tiled X11 window manager 16 | wmii is a dynamic window manager for X11, which is highly customizable and 17 | usable with keyboard and mouse. It supports conventional, tabbed and tiled 18 | window management with low memory usage. It is highly modularized and uses an 19 | inter-process communication interface which is oriented on the 9p protocol of 20 | plan9. 21 | -------------------------------------------------------------------------------- /debian/docs: -------------------------------------------------------------------------------- 1 | FAQ 2 | README 3 | -------------------------------------------------------------------------------- /debian/file/wmii.desktop: -------------------------------------------------------------------------------- 1 | [Desktop Entry] 2 | Encoding=UTF-8 3 | Name=wmii 4 | Comment=wmii pre-3.6 Development Snapshot 5 | Exec=wmii 6 | Icon=wmii.png 7 | Type=XSession 8 | -------------------------------------------------------------------------------- /debian/rules: -------------------------------------------------------------------------------- 1 | #!/usr/bin/make -f 2 | 3 | PACKAGE=$(shell awk 'NR == 1 { print $$2 }' debian/control) 4 | 5 | FLAGS = DESTDIR=$(CURDIR)/debian/$(PACKAGE)/ \ 6 | PREFIX=/usr \ 7 | ETC=/etc/X11 \ 8 | STATIC= \ 9 | TERMINAL=x-terminal-emulator 10 | 11 | %: 12 | dh $@ 13 | 14 | override_dh_installwm: 15 | dh_installwm --priority=60 16 | 17 | override_dh_compress: 18 | dh_compress -X.pdf 19 | 20 | override_dh_auto_build: 21 | $(MAKE) $(FLAGS) all 22 | 23 | override_dh_auto_install: 24 | $(MAKE) $(FLAGS) install 25 | 26 | rm debian/$(PACKAGE)/usr/share/doc/wmii/LICENSE 27 | install -D -m0644 img/icon.png debian/$(PACKAGE)/usr/share/icons/wmii.png 28 | install -D -m0644 debian/file/wmii.desktop debian/$(PACKAGE)/usr/share/xsessions/wmii.desktop 29 | 30 | .depend: 31 | true 32 | 33 | -------------------------------------------------------------------------------- /debian/wmii.menu: -------------------------------------------------------------------------------- 1 | ?package(wmii):needs="wm" section="WindowManagers"\ 2 | title="wmii" longtitle="wmii pre-3.6 Development Snapshot"\ 3 | command="/usr/bin/wmii" 4 | -------------------------------------------------------------------------------- /debian/wmii.wm: -------------------------------------------------------------------------------- 1 | /usr/bin/wmii 2 | -------------------------------------------------------------------------------- /doc/Makefile: -------------------------------------------------------------------------------- 1 | ROOT=.. 2 | include $(ROOT)/mk/hdr.mk 3 | include $(ROOT)/mk/wmii.mk 4 | 5 | TARG = wmii.pdf 6 | 7 | all: $(TARG) 8 | 9 | install: $(TARG:.pdf=.install) 10 | uninstall: $(TARG:.pdf=.uninstall) 11 | 12 | clean:; true 13 | 14 | -------------------------------------------------------------------------------- /doc/floating.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0intro/wmii/26848c93457606b350f57d6d313112a745a0cf3d/doc/floating.png -------------------------------------------------------------------------------- /doc/focused.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0intro/wmii/26848c93457606b350f57d6d313112a745a0cf3d/doc/focused.png -------------------------------------------------------------------------------- /doc/license.tex: -------------------------------------------------------------------------------- 1 | \chapter*{License} 2 | 3 | This file is distributed under the same terms as wmii: 4 | 5 | \begingroup 6 | \ttfamily 7 | \parindent=0pt 8 | \parskip=1em 9 | 10 | Copyright © 2009-2010 Kris Maglione <\href{mailto:maglione.k@gmail.com}{maglione.k@gmail.com}> 11 | 12 | Permission is hereby granted, free of charge, to any person obtaining a 13 | copy of this software and associated documentation files (the "Software"), 14 | to deal in the Software without restriction, including without limitation 15 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 16 | and/or sell copies of the Software, and to permit persons to whom the 17 | Software is furnished to do so, subject to the following conditions: 18 | 19 | The above copyright notice and this permission notice shall be included in 20 | all copies or substantial portions of the Software. 21 | 22 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 23 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 24 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 25 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 26 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 27 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 28 | DEALINGS IN THE SOFTWARE. 29 | \endgroup 30 | -------------------------------------------------------------------------------- /doc/managed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0intro/wmii/26848c93457606b350f57d6d313112a745a0cf3d/doc/managed.png -------------------------------------------------------------------------------- /doc/mkfile: -------------------------------------------------------------------------------- 1 | MKSHELL=rc 2 | 3 | TARG = wmii.pdf 4 | SRC = ${TARG:%.pdf=%.tex} 5 | TEX = xelatex 6 | 7 | default:V: all 8 | all:V: $TARG 9 | 10 | # mk doesn't recognize nested `{} 11 | deps = `{ ash -c 'dep() { echo $1; for f in $(9 sed -n "s/.*\\include{([^}]+)}.*/\1.tex/p; s/.*\\input (.*)/\1.tex/p" $1); do dep $f; done; }; dep $SRC' } 12 | # ` 13 | $TARG: $deps 14 | 15 | junk = aux idx ilg ind log toc out 16 | CLEAN = ${TARG:%.pdf=%} 17 | CLEAN = ${junk:%=$CLEAN.%} ${deps:%.tex=%.aux} 18 | clean:V: 19 | rm -f $CLEAN 20 | 21 | %.pdf: %.tex mkfile 22 | flag x + 23 | if (~ $MAINFONT '') 24 | fn tex { builtin $TEX $stem.tex } 25 | if not 26 | fn tex { builtin $TEX '\def\mainfont{'$"MAINFONT'}\input{'$stem.tex'}' } 27 | 28 | tex 29 | makeindex $stem 30 | tex 31 | rm -f $stem.out 2>/dev/null 32 | 33 | # vim:se ft=make: 34 | -------------------------------------------------------------------------------- /doc/selected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0intro/wmii/26848c93457606b350f57d6d313112a745a0cf3d/doc/selected.png -------------------------------------------------------------------------------- /doc/unfocused.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0intro/wmii/26848c93457606b350f57d6d313112a745a0cf3d/doc/unfocused.png -------------------------------------------------------------------------------- /doc/unselected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0intro/wmii/26848c93457606b350f57d6d313112a745a0cf3d/doc/unselected.png -------------------------------------------------------------------------------- /doc/wmii.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0intro/wmii/26848c93457606b350f57d6d313112a745a0cf3d/doc/wmii.pdf -------------------------------------------------------------------------------- /examples/Makefile: -------------------------------------------------------------------------------- 1 | ROOT=.. 2 | include $(ROOT)/mk/hdr.mk 3 | include $(ROOT)/mk/wmii.mk 4 | 5 | DOCS = wimenu-file-completion.sh 6 | DOCDIR = $(DOC)/examples 7 | 8 | -------------------------------------------------------------------------------- /img/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0intro/wmii/26848c93457606b350f57d6d313112a745a0cf3d/img/icon.png -------------------------------------------------------------------------------- /img/mkfile: -------------------------------------------------------------------------------- 1 | MKSHELL=rc 2 | path=$PLAN9/bin $path 3 | 4 | eps = wmii.eps 5 | calc = rc -c 'echo 4k $* p | dc} 6 | 7 | iconwidth = 16 8 | imagewidth = 154 9 | 10 | %.pdf: %.eps 11 | sh epstopdf $stem.eps 12 | 13 | %-small.png: %.eps 14 | epsbox = `{sed -n '/^%%BoundingBox:/{s/.*://p; q;}' $stem.eps} 15 | iconscale = `{*=$epsbox; $calc $iconwidth $3 $1 -/} 16 | iconheight = `{*=$epsbox; $calc $4 $2 - $iconscale '*'} 17 | * = `{hoc -e'-('$epsbox')'} 18 | x = $1 19 | y = $2 20 | gs -q -dBATCH -dNOPAUSE -s'DEVICE=pngalpha' -s'OutputFile='$target -g$iconwidth^x^$iconheight - < 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | #define OREAD O_RDONLY 32 | #define OWRITE O_WRONLY 33 | 34 | #define OCEXEC 0 35 | #define ORCLOSE 0 36 | #define OTRUNC 0 37 | 38 | #define exits(x) exit(x && *x ? 1 : 0) 39 | 40 | #undef nil 41 | #define nil ((void*)0) 42 | 43 | #undef nelem 44 | #define nelem(x) (sizeof (x)/sizeof (x)[0]) 45 | 46 | -------------------------------------------------------------------------------- /include/stuff/clientutil.h: -------------------------------------------------------------------------------- 1 | /* Copyright ©2009-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | 5 | #ifndef CLIENTEXTERN 6 | # define CLIENTEXTERN extern 7 | #endif 8 | 9 | char* readctl(char*, char*); 10 | void client_init(char*); 11 | 12 | CLIENTEXTERN IxpClient* client; 13 | 14 | -------------------------------------------------------------------------------- /lib/Makefile: -------------------------------------------------------------------------------- 1 | ROOT=.. 2 | include $(ROOT)/mk/hdr.mk 3 | include $(ROOT)/mk/wmii.mk 4 | 5 | PDIRS = \ 6 | libwmii_hack 7 | 8 | DIRS = \ 9 | libstuff \ 10 | libbio \ 11 | libfmt \ 12 | libregexp \ 13 | libutf \ 14 | $(PDIRS) 15 | 16 | include $(ROOT)/mk/dir.mk 17 | INSTDIRS = $(PDIRS) 18 | 19 | -------------------------------------------------------------------------------- /lib/libbio/Makefile: -------------------------------------------------------------------------------- 1 | ROOT= ../.. 2 | include $(ROOT)/mk/hdr.mk 3 | 4 | VERSION=2.0 5 | TARG=libbio 6 | 7 | OBJ=\ 8 | bbuffered\ 9 | bfildes\ 10 | bflush\ 11 | bgetc\ 12 | bgetd\ 13 | bgetrune\ 14 | binit\ 15 | boffset\ 16 | bprint\ 17 | bvprint\ 18 | bputc\ 19 | bputrune\ 20 | brdline\ 21 | brdstr\ 22 | bread\ 23 | bseek\ 24 | bwrite 25 | 26 | include $(ROOT)/mk/lib.mk 27 | 28 | -------------------------------------------------------------------------------- /lib/libbio/NOTICE: -------------------------------------------------------------------------------- 1 | This is a Unix port of the Plan 9 buffered I/O library. 2 | Please send comments about the packaging to Russ Cox . 3 | 4 | Copyright © 2021 Plan 9 Foundation 5 | Revisions Copyright © 2000-2005 Vita Nuova Holdings Limited (www.vitanuova.com). All rights reserved. 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | -------------------------------------------------------------------------------- /lib/libbio/README: -------------------------------------------------------------------------------- 1 | This software was packaged for Unix by Russ Cox. 2 | Please send comments to rsc@swtch.com. 3 | 4 | http://swtch.com/plan9port/unix 5 | 6 | -------------------------------------------------------------------------------- /lib/libbio/bbuffered.c: -------------------------------------------------------------------------------- 1 | #include "plan9.h" 2 | #include 3 | 4 | int 5 | Bbuffered(Biobuf *bp) 6 | { 7 | switch(bp->state) { 8 | case Bracteof: 9 | case Bractive: 10 | return -bp->icount; 11 | 12 | case Bwactive: 13 | return bp->bsize + bp->ocount; 14 | 15 | case Binactive: 16 | return 0; 17 | } 18 | fprint(2, "Bbuffered: unknown state %d\n", bp->state); 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /lib/libbio/bcat.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "bio.h" 3 | 4 | Biobuf bout; 5 | 6 | void 7 | bcat(Biobuf *b, char *name) 8 | { 9 | char buf[1000]; 10 | int n; 11 | 12 | while((n = Bread(b, buf, sizeof buf)) > 0){ 13 | if(Bwrite(&bout, buf, n) < 0) 14 | fprint(2, "writing during %s: %r\n", name); 15 | } 16 | if(n < 0) 17 | fprint(2, "reading %s: %r\n", name); 18 | } 19 | 20 | int 21 | main(int argc, char **argv) 22 | { 23 | int i; 24 | Biobuf b, *bp; 25 | Fmt fmt; 26 | 27 | Binit(&bout, 1, O_WRONLY); 28 | Bfmtinit(&fmt, &bout); 29 | fmtprint(&fmt, "hello, world\n"); 30 | Bfmtflush(&fmt); 31 | 32 | if(argc == 1){ 33 | Binit(&b, 0, O_RDONLY); 34 | bcat(&b, ""); 35 | }else{ 36 | for(i=1; i 3 | 4 | int 5 | Bfildes(Biobuf *bp) 6 | { 7 | 8 | return bp->fid; 9 | } 10 | -------------------------------------------------------------------------------- /lib/libbio/bflush.c: -------------------------------------------------------------------------------- 1 | #include "plan9.h" 2 | #include 3 | 4 | int 5 | Bflush(Biobuf *bp) 6 | { 7 | int n, c; 8 | 9 | switch(bp->state) { 10 | case Bwactive: 11 | n = bp->bsize+bp->ocount; 12 | if(n == 0) 13 | return 0; 14 | c = write(bp->fid, bp->bbuf, n); 15 | if(n == c) { 16 | bp->offset += n; 17 | bp->ocount = -bp->bsize; 18 | return 0; 19 | } 20 | bp->state = Binactive; 21 | bp->ocount = 0; 22 | break; 23 | 24 | case Bracteof: 25 | bp->state = Bractive; 26 | 27 | case Bractive: 28 | bp->icount = 0; 29 | bp->gbuf = bp->ebuf; 30 | return 0; 31 | } 32 | return Beof; 33 | } 34 | -------------------------------------------------------------------------------- /lib/libbio/bgetc.c: -------------------------------------------------------------------------------- 1 | #include "plan9.h" 2 | #include 3 | 4 | int 5 | Bgetc(Biobuf *bp) 6 | { 7 | int i; 8 | 9 | loop: 10 | i = bp->icount; 11 | if(i != 0) { 12 | bp->icount = i+1; 13 | return bp->ebuf[i]; 14 | } 15 | if(bp->state != Bractive) { 16 | if(bp->state == Bracteof) 17 | bp->state = Bractive; 18 | return Beof; 19 | } 20 | /* 21 | * get next buffer, try to keep Bungetsize 22 | * characters pre-catenated from the previous 23 | * buffer to allow that many ungets. 24 | */ 25 | memmove(bp->bbuf-Bungetsize, bp->ebuf-Bungetsize, Bungetsize); 26 | i = read(bp->fid, bp->bbuf, bp->bsize); 27 | bp->gbuf = bp->bbuf; 28 | if(i <= 0) { 29 | bp->state = Bracteof; 30 | if(i < 0) 31 | bp->state = Binactive; 32 | return Beof; 33 | } 34 | if(i < bp->bsize) { 35 | memmove(bp->ebuf-i-Bungetsize, bp->bbuf-Bungetsize, i+Bungetsize); 36 | bp->gbuf = bp->ebuf-i; 37 | } 38 | bp->icount = -i; 39 | bp->offset += i; 40 | goto loop; 41 | } 42 | 43 | int 44 | Bungetc(Biobuf *bp) 45 | { 46 | 47 | if(bp->state == Bracteof) 48 | bp->state = Bractive; 49 | if(bp->state != Bractive) 50 | return Beof; 51 | bp->icount--; 52 | return 1; 53 | } 54 | -------------------------------------------------------------------------------- /lib/libbio/bgetd.c: -------------------------------------------------------------------------------- 1 | #include "plan9.h" 2 | #include 3 | 4 | struct bgetd 5 | { 6 | Biobuf* b; 7 | int eof; 8 | }; 9 | 10 | static int 11 | Bgetdf(void *vp) 12 | { 13 | int c; 14 | struct bgetd *bg = vp; 15 | 16 | c = Bgetc(bg->b); 17 | if(c == Beof) 18 | bg->eof = 1; 19 | return c; 20 | } 21 | 22 | int 23 | Bgetd(Biobuf *bp, double *dp) 24 | { 25 | double d; 26 | struct bgetd b; 27 | 28 | b.b = bp; 29 | b.eof = 0; 30 | d = fmtcharstod(Bgetdf, &b); 31 | if(b.eof) 32 | return -1; 33 | Bungetc(bp); 34 | *dp = d; 35 | return 1; 36 | } 37 | -------------------------------------------------------------------------------- /lib/libbio/bgetrune.c: -------------------------------------------------------------------------------- 1 | #include "plan9.h" 2 | #include 3 | #include 4 | 5 | long 6 | Bgetrune(Biobuf *bp) 7 | { 8 | int c, i; 9 | Rune rune; 10 | char str[UTFmax]; 11 | 12 | c = Bgetc(bp); 13 | if(c < Runeself) { /* one char */ 14 | bp->runesize = 1; 15 | return c; 16 | } 17 | str[0] = c; 18 | 19 | for(i=1;;) { 20 | c = Bgetc(bp); 21 | if(c < 0) 22 | return c; 23 | str[i++] = c; 24 | 25 | if(fullrune(str, i)) { 26 | bp->runesize = chartorune(&rune, str); 27 | while(i > bp->runesize) { 28 | Bungetc(bp); 29 | i--; 30 | } 31 | return rune; 32 | } 33 | } 34 | } 35 | 36 | int 37 | Bungetrune(Biobuf *bp) 38 | { 39 | 40 | if(bp->state == Bracteof) 41 | bp->state = Bractive; 42 | if(bp->state != Bractive) 43 | return Beof; 44 | bp->icount -= bp->runesize; 45 | bp->runesize = 0; 46 | return 1; 47 | } 48 | -------------------------------------------------------------------------------- /lib/libbio/boffset.c: -------------------------------------------------------------------------------- 1 | #include "plan9.h" 2 | #include 3 | 4 | off_t 5 | Boffset(Biobuf *bp) 6 | { 7 | off_t n; 8 | 9 | switch(bp->state) { 10 | default: 11 | fprint(2, "Boffset: unknown state %d\n", bp->state); 12 | n = Beof; 13 | break; 14 | 15 | case Bracteof: 16 | case Bractive: 17 | n = bp->offset + bp->icount; 18 | break; 19 | 20 | case Bwactive: 21 | n = bp->offset + (bp->bsize + bp->ocount); 22 | break; 23 | } 24 | return n; 25 | } 26 | -------------------------------------------------------------------------------- /lib/libbio/bprint.c: -------------------------------------------------------------------------------- 1 | #include "plan9.h" 2 | #include 3 | 4 | int 5 | Bprint(Biobuf *bp, const char *fmt, ...) 6 | { 7 | int n; 8 | va_list arg; 9 | 10 | va_start(arg, fmt); 11 | n = Bvprint(bp, fmt, arg); 12 | va_end(arg); 13 | return n; 14 | } 15 | -------------------------------------------------------------------------------- /lib/libbio/bputc.c: -------------------------------------------------------------------------------- 1 | #include "plan9.h" 2 | #include 3 | 4 | int 5 | Bputc(Biobuf *bp, int c) 6 | { 7 | int i; 8 | 9 | for(;;) { 10 | i = bp->ocount; 11 | if(i) { 12 | bp->ebuf[i++] = c; 13 | bp->ocount = i; 14 | return 0; 15 | } 16 | if(Bflush(bp) == Beof) 17 | break; 18 | } 19 | return Beof; 20 | } 21 | -------------------------------------------------------------------------------- /lib/libbio/bputrune.c: -------------------------------------------------------------------------------- 1 | #include "plan9.h" 2 | #include 3 | #include 4 | 5 | int 6 | Bputrune(Biobuf *bp, long c) 7 | { 8 | Rune rune; 9 | char str[UTFmax]; 10 | int n; 11 | 12 | rune = c; 13 | if(rune < Runeself) { 14 | Bputc(bp, rune); 15 | return 1; 16 | } 17 | n = runetochar(str, &rune); 18 | if(n == 0) 19 | return Bbad; 20 | if(Bwrite(bp, str, n) != n) 21 | return Beof; 22 | return n; 23 | } 24 | -------------------------------------------------------------------------------- /lib/libbio/bread.c: -------------------------------------------------------------------------------- 1 | #include "plan9.h" 2 | #include 3 | 4 | long 5 | Bread(Biobuf *bp, void *ap, long count) 6 | { 7 | long c; 8 | unsigned char *p; 9 | int i, n, ic; 10 | 11 | p = ap; 12 | c = count; 13 | ic = bp->icount; 14 | 15 | while(c > 0) { 16 | n = -ic; 17 | if(n > c) 18 | n = c; 19 | if(n == 0) { 20 | if(bp->state != Bractive) 21 | break; 22 | i = read(bp->fid, bp->bbuf, bp->bsize); 23 | if(i <= 0) { 24 | bp->state = Bracteof; 25 | if(i < 0) 26 | bp->state = Binactive; 27 | break; 28 | } 29 | bp->gbuf = bp->bbuf; 30 | bp->offset += i; 31 | if(i < bp->bsize) { 32 | memmove(bp->ebuf-i, bp->bbuf, i); 33 | bp->gbuf = bp->ebuf-i; 34 | } 35 | ic = -i; 36 | continue; 37 | } 38 | memmove(p, bp->ebuf+ic, n); 39 | c -= n; 40 | ic += n; 41 | p += n; 42 | } 43 | bp->icount = ic; 44 | return count-c; 45 | } 46 | -------------------------------------------------------------------------------- /lib/libbio/bseek.c: -------------------------------------------------------------------------------- 1 | #include "plan9.h" 2 | #include 3 | 4 | off_t 5 | Bseek(Biobuf *bp, off_t offset, int base) 6 | { 7 | vlong n, d; 8 | int bufsz; 9 | 10 | switch(bp->state) { 11 | default: 12 | fprint(2, "Bseek: unknown state %d\n", bp->state); 13 | return Beof; 14 | 15 | case Bracteof: 16 | bp->state = Bractive; 17 | bp->icount = 0; 18 | bp->gbuf = bp->ebuf; 19 | 20 | case Bractive: 21 | n = offset; 22 | if(base == 1) { 23 | n += Boffset(bp); 24 | base = 0; 25 | } 26 | 27 | /* 28 | * try to seek within buffer 29 | */ 30 | if(base == 0) { 31 | d = n - Boffset(bp); 32 | bufsz = bp->ebuf - bp->gbuf; 33 | if(-bufsz <= d && d <= bufsz){ 34 | bp->icount += d; 35 | if(d >= 0) { 36 | if(bp->icount <= 0) 37 | return n; 38 | } else { 39 | if(bp->ebuf - bp->gbuf >= -bp->icount) 40 | return n; 41 | } 42 | } 43 | } 44 | 45 | /* 46 | * reset the buffer 47 | */ 48 | n = lseek(bp->fid, n, base); 49 | bp->icount = 0; 50 | bp->gbuf = bp->ebuf; 51 | break; 52 | 53 | case Bwactive: 54 | Bflush(bp); 55 | n = lseek(bp->fid, offset, base); 56 | break; 57 | } 58 | bp->offset = n; 59 | return n; 60 | } 61 | -------------------------------------------------------------------------------- /lib/libbio/bvprint.c: -------------------------------------------------------------------------------- 1 | #include "plan9.h" 2 | #include 3 | 4 | static int 5 | fmtBflush(Fmt *f) 6 | { 7 | Biobuf *bp; 8 | 9 | bp = f->farg; 10 | bp->ocount = (char*)f->to - (char*)f->stop; 11 | if(Bflush(bp) < 0) 12 | return 0; 13 | f->stop = bp->ebuf; 14 | f->to = (char*)f->stop + bp->ocount; 15 | f->start = f->to; 16 | return 1; 17 | } 18 | 19 | int 20 | Bvprint(Biobuf *bp, const char *fmt, va_list arg) 21 | { 22 | int n; 23 | Fmt f; 24 | 25 | f.runes = 0; 26 | f.stop = bp->ebuf; 27 | f.start = (char*)f.stop + bp->ocount; 28 | f.to = f.start; 29 | f.flush = fmtBflush; 30 | f.farg = bp; 31 | f.nfmt = 0; 32 | fmtlocaleinit(&f, nil, nil, nil); 33 | n = fmtvprint(&f, fmt, arg); 34 | bp->ocount = (char*)f.to - (char*)f.stop; 35 | if(n == 0) 36 | n = f.nfmt; 37 | return n; 38 | } 39 | 40 | -------------------------------------------------------------------------------- /lib/libbio/bwrite.c: -------------------------------------------------------------------------------- 1 | #include "plan9.h" 2 | #include 3 | 4 | long 5 | Bwrite(Biobuf *bp, void *ap, long count) 6 | { 7 | long c; 8 | unsigned char *p; 9 | int i, n, oc; 10 | 11 | p = ap; 12 | c = count; 13 | oc = bp->ocount; 14 | 15 | while(c > 0) { 16 | n = -oc; 17 | if(n > c) 18 | n = c; 19 | if(n == 0) { 20 | if(bp->state != Bwactive) 21 | return Beof; 22 | i = write(bp->fid, bp->bbuf, bp->bsize); 23 | if(i != bp->bsize) { 24 | bp->state = Binactive; 25 | return Beof; 26 | } 27 | bp->offset += i; 28 | oc = -bp->bsize; 29 | continue; 30 | } 31 | memmove(bp->ebuf+oc, p, n); 32 | oc += n; 33 | c -= n; 34 | p += n; 35 | } 36 | bp->ocount = oc; 37 | return count-c; 38 | } 39 | -------------------------------------------------------------------------------- /lib/libfmt/Makefile: -------------------------------------------------------------------------------- 1 | ROOT= ../.. 2 | include $(ROOT)/mk/hdr.mk 3 | 4 | VERSION=2.0 5 | TARG=libfmt 6 | 7 | NUM=\ 8 | charstod\ 9 | pow10\ 10 | nan64 11 | 12 | OBJ=\ 13 | dofmt\ 14 | dorfmt\ 15 | errfmt\ 16 | fltfmt\ 17 | fmt\ 18 | fmtfd\ 19 | fmtfdflush\ 20 | fmtlocale\ 21 | fmtlock\ 22 | fmtprint\ 23 | fmtquote\ 24 | fmtrune\ 25 | fmtstr\ 26 | fmtvprint\ 27 | fprint\ 28 | print\ 29 | runefmtstr\ 30 | runeseprint\ 31 | runesmprint\ 32 | runesnprint\ 33 | runesprint\ 34 | runevseprint\ 35 | runevsmprint\ 36 | runevsnprint\ 37 | seprint\ 38 | smprint\ 39 | snprint\ 40 | sprint\ 41 | strtod\ 42 | vfprint\ 43 | vseprint\ 44 | vsmprint\ 45 | vsnprint\ 46 | $(NUM) 47 | 48 | include $(ROOT)/mk/lib.mk 49 | 50 | -------------------------------------------------------------------------------- /lib/libfmt/NOTICE: -------------------------------------------------------------------------------- 1 | This is a Unix port of the Plan 9 formatted I/O library, by Rob Pike and Ken Thompson. 2 | Please send comments about the packaging to Russ Cox . 3 | 4 | Copyright © 2021 Plan 9 Foundation 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /lib/libfmt/README: -------------------------------------------------------------------------------- 1 | This software was packaged for Unix by Russ Cox. 2 | Please send comments to rsc@swtch.com. 3 | 4 | http://swtch.com/plan9port/unix 5 | 6 | -------------------------------------------------------------------------------- /lib/libfmt/errfmt.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson. 3 | * Copyright (c) 2002 by Lucent Technologies. 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose without fee is hereby granted, provided that this entire notice 6 | * is included in all copies of any software which is or includes a copy 7 | * or modification of this software and in all copies of the supporting 8 | * documentation for such software. 9 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 10 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE 11 | * ANY REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY 12 | * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 13 | */ 14 | #include 15 | #include 16 | #include 17 | #include "plan9.h" 18 | #include "fmt.h" 19 | #include "fmtdef.h" 20 | 21 | int 22 | __errfmt(Fmt *f) 23 | { 24 | char *s; 25 | 26 | s = strerror(errno); 27 | return fmtstrcpy(f, s); 28 | } 29 | -------------------------------------------------------------------------------- /lib/libfmt/fmtfdflush.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson. 3 | * Copyright (c) 2002 by Lucent Technologies. 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose without fee is hereby granted, provided that this entire notice 6 | * is included in all copies of any software which is or includes a copy 7 | * or modification of this software and in all copies of the supporting 8 | * documentation for such software. 9 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 10 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE 11 | * ANY REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY 12 | * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 13 | */ 14 | #include 15 | #include 16 | #include "plan9.h" 17 | #include "fmt.h" 18 | #include "fmtdef.h" 19 | 20 | /* 21 | * generic routine for flushing a formatting buffer 22 | * to a file descriptor 23 | */ 24 | int 25 | __fmtFdFlush(Fmt *f) 26 | { 27 | int n; 28 | 29 | n = (char*)f->to - (char*)f->start; 30 | if(n && write((uintptr_t)f->farg, f->start, n) != n) 31 | return 0; 32 | f->to = f->start; 33 | return 1; 34 | } 35 | -------------------------------------------------------------------------------- /lib/libfmt/fmtlock.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson. 3 | * Copyright (c) 2002 by Lucent Technologies. 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose without fee is hereby granted, provided that this entire notice 6 | * is included in all copies of any software which is or includes a copy 7 | * or modification of this software and in all copies of the supporting 8 | * documentation for such software. 9 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 10 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE 11 | * ANY REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY 12 | * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 13 | */ 14 | #include 15 | #include "plan9.h" 16 | #include "fmt.h" 17 | #include "fmtdef.h" 18 | 19 | void 20 | __fmtlock(void) 21 | { 22 | } 23 | 24 | void 25 | __fmtunlock(void) 26 | { 27 | } 28 | -------------------------------------------------------------------------------- /lib/libfmt/fmtrune.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson. 3 | * Copyright (c) 2002 by Lucent Technologies. 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose without fee is hereby granted, provided that this entire notice 6 | * is included in all copies of any software which is or includes a copy 7 | * or modification of this software and in all copies of the supporting 8 | * documentation for such software. 9 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 10 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE 11 | * ANY REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY 12 | * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 13 | */ 14 | #include 15 | #include 16 | #include "plan9.h" 17 | #include "fmt.h" 18 | #include "fmtdef.h" 19 | 20 | int 21 | fmtrune(Fmt *f, int r) 22 | { 23 | Rune *rt; 24 | char *t; 25 | int n; 26 | 27 | if(f->runes){ 28 | rt = (Rune*)f->to; 29 | FMTRCHAR(f, rt, f->stop, r); 30 | f->to = rt; 31 | n = 1; 32 | }else{ 33 | t = (char*)f->to; 34 | FMTRUNE(f, t, f->stop, r); 35 | n = t - (char*)f->to; 36 | f->to = t; 37 | } 38 | f->nfmt += n; 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /lib/libfmt/fmtstr.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson. 3 | * Copyright (c) 2002 by Lucent Technologies. 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose without fee is hereby granted, provided that this entire notice 6 | * is included in all copies of any software which is or includes a copy 7 | * or modification of this software and in all copies of the supporting 8 | * documentation for such software. 9 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 10 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE 11 | * ANY REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY 12 | * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 13 | */ 14 | #include 15 | #include 16 | #include "plan9.h" 17 | #include "fmt.h" 18 | #include "fmtdef.h" 19 | 20 | char* 21 | fmtstrflush(Fmt *f) 22 | { 23 | if(f->start == nil) 24 | return nil; 25 | *(char*)f->to = '\0'; 26 | f->to = f->start; 27 | return (char*)f->start; 28 | } 29 | -------------------------------------------------------------------------------- /lib/libfmt/fprint.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson. 3 | * Copyright (c) 2002 by Lucent Technologies. 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose without fee is hereby granted, provided that this entire notice 6 | * is included in all copies of any software which is or includes a copy 7 | * or modification of this software and in all copies of the supporting 8 | * documentation for such software. 9 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 10 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE 11 | * ANY REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY 12 | * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 13 | */ 14 | #include 15 | #include "plan9.h" 16 | #include "fmt.h" 17 | #include "fmtdef.h" 18 | 19 | int 20 | fprint(int fd, const char *fmt, ...) 21 | { 22 | int n; 23 | va_list args; 24 | 25 | va_start(args, fmt); 26 | n = vfprint(fd, fmt, args); 27 | va_end(args); 28 | return n; 29 | } 30 | -------------------------------------------------------------------------------- /lib/libfmt/libfmt.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0intro/wmii/26848c93457606b350f57d6d313112a745a0cf3d/lib/libfmt/libfmt.a -------------------------------------------------------------------------------- /lib/libfmt/print.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson. 3 | * Copyright (c) 2002 by Lucent Technologies. 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose without fee is hereby granted, provided that this entire notice 6 | * is included in all copies of any software which is or includes a copy 7 | * or modification of this software and in all copies of the supporting 8 | * documentation for such software. 9 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 10 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE 11 | * ANY REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY 12 | * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 13 | */ 14 | #include 15 | #include "plan9.h" 16 | #include "fmt.h" 17 | #include "fmtdef.h" 18 | 19 | int 20 | print(const char *fmt, ...) 21 | { 22 | int n; 23 | va_list args; 24 | 25 | va_start(args, fmt); 26 | n = vfprint(1, fmt, args); 27 | va_end(args); 28 | return n; 29 | } 30 | -------------------------------------------------------------------------------- /lib/libfmt/runefmtstr.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson. 3 | * Copyright (c) 2002 by Lucent Technologies. 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose without fee is hereby granted, provided that this entire notice 6 | * is included in all copies of any software which is or includes a copy 7 | * or modification of this software and in all copies of the supporting 8 | * documentation for such software. 9 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 10 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE 11 | * ANY REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY 12 | * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 13 | */ 14 | #include 15 | #include 16 | #include "plan9.h" 17 | #include "fmt.h" 18 | #include "fmtdef.h" 19 | 20 | Rune* 21 | runefmtstrflush(Fmt *f) 22 | { 23 | if(f->start == nil) 24 | return nil; 25 | *(Rune*)f->to = '\0'; 26 | f->to = f->start; 27 | return f->start; 28 | } 29 | -------------------------------------------------------------------------------- /lib/libfmt/runeseprint.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson. 3 | * Copyright (c) 2002 by Lucent Technologies. 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose without fee is hereby granted, provided that this entire notice 6 | * is included in all copies of any software which is or includes a copy 7 | * or modification of this software and in all copies of the supporting 8 | * documentation for such software. 9 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 10 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE 11 | * ANY REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY 12 | * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 13 | */ 14 | #include 15 | #include 16 | #include "plan9.h" 17 | #include "fmt.h" 18 | #include "fmtdef.h" 19 | 20 | Rune* 21 | runeseprint(Rune *buf, Rune *e, const char *fmt, ...) 22 | { 23 | Rune *p; 24 | va_list args; 25 | 26 | va_start(args, fmt); 27 | p = runevseprint(buf, e, fmt, args); 28 | va_end(args); 29 | return p; 30 | } 31 | -------------------------------------------------------------------------------- /lib/libfmt/runesmprint.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson. 3 | * Copyright (c) 2002 by Lucent Technologies. 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose without fee is hereby granted, provided that this entire notice 6 | * is included in all copies of any software which is or includes a copy 7 | * or modification of this software and in all copies of the supporting 8 | * documentation for such software. 9 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 10 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE 11 | * ANY REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY 12 | * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 13 | */ 14 | #include 15 | #include 16 | #include "plan9.h" 17 | #include "fmt.h" 18 | #include "fmtdef.h" 19 | 20 | Rune* 21 | runesmprint(const char *fmt, ...) 22 | { 23 | va_list args; 24 | Rune *p; 25 | 26 | va_start(args, fmt); 27 | p = runevsmprint(fmt, args); 28 | va_end(args); 29 | return p; 30 | } 31 | -------------------------------------------------------------------------------- /lib/libfmt/runesnprint.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson. 3 | * Copyright (c) 2002 by Lucent Technologies. 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose without fee is hereby granted, provided that this entire notice 6 | * is included in all copies of any software which is or includes a copy 7 | * or modification of this software and in all copies of the supporting 8 | * documentation for such software. 9 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 10 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE 11 | * ANY REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY 12 | * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 13 | */ 14 | #include 15 | #include 16 | #include "plan9.h" 17 | #include "fmt.h" 18 | #include "fmtdef.h" 19 | 20 | int 21 | runesnprint(Rune *buf, int len, const char *fmt, ...) 22 | { 23 | int n; 24 | va_list args; 25 | 26 | va_start(args, fmt); 27 | n = runevsnprint(buf, len, fmt, args); 28 | va_end(args); 29 | return n; 30 | } 31 | 32 | -------------------------------------------------------------------------------- /lib/libfmt/runesprint.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson. 3 | * Copyright (c) 2002 by Lucent Technologies. 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose without fee is hereby granted, provided that this entire notice 6 | * is included in all copies of any software which is or includes a copy 7 | * or modification of this software and in all copies of the supporting 8 | * documentation for such software. 9 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 10 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE 11 | * ANY REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY 12 | * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 13 | */ 14 | #include 15 | #include 16 | #include "plan9.h" 17 | #include "fmt.h" 18 | #include "fmtdef.h" 19 | 20 | int 21 | runesprint(Rune *buf, const char *fmt, ...) 22 | { 23 | int n; 24 | va_list args; 25 | 26 | va_start(args, fmt); 27 | n = runevsnprint(buf, 256, fmt, args); 28 | va_end(args); 29 | return n; 30 | } 31 | -------------------------------------------------------------------------------- /lib/libfmt/runevseprint.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson. 3 | * Copyright (c) 2002 by Lucent Technologies. 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose without fee is hereby granted, provided that this entire notice 6 | * is included in all copies of any software which is or includes a copy 7 | * or modification of this software and in all copies of the supporting 8 | * documentation for such software. 9 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 10 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE 11 | * ANY REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY 12 | * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 13 | */ 14 | #include 15 | #include 16 | #include "plan9.h" 17 | #include "fmt.h" 18 | #include "fmtdef.h" 19 | 20 | Rune* 21 | runevseprint(Rune *buf, Rune *e, const char *fmt, va_list args) 22 | { 23 | Fmt f; 24 | 25 | if(e <= buf) 26 | return nil; 27 | f.runes = 1; 28 | f.start = buf; 29 | f.to = buf; 30 | f.stop = e - 1; 31 | f.flush = nil; 32 | f.farg = nil; 33 | f.nfmt = 0; 34 | va_copy(f.args,args); 35 | fmtlocaleinit(&f, nil, nil, nil); 36 | dofmt(&f, fmt); 37 | va_end(f.args); 38 | *(Rune*)f.to = '\0'; 39 | return (Rune*)f.to; 40 | } 41 | 42 | -------------------------------------------------------------------------------- /lib/libfmt/seprint.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson. 3 | * Copyright (c) 2002 by Lucent Technologies. 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose without fee is hereby granted, provided that this entire notice 6 | * is included in all copies of any software which is or includes a copy 7 | * or modification of this software and in all copies of the supporting 8 | * documentation for such software. 9 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 10 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE 11 | * ANY REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY 12 | * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 13 | */ 14 | #include 15 | #include "plan9.h" 16 | #include "fmt.h" 17 | #include "fmtdef.h" 18 | 19 | char* 20 | seprint(char *buf, char *e, const char *fmt, ...) 21 | { 22 | char *p; 23 | va_list args; 24 | 25 | va_start(args, fmt); 26 | p = vseprint(buf, e, fmt, args); 27 | va_end(args); 28 | return p; 29 | } 30 | -------------------------------------------------------------------------------- /lib/libfmt/smprint.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson. 3 | * Copyright (c) 2002 by Lucent Technologies. 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose without fee is hereby granted, provided that this entire notice 6 | * is included in all copies of any software which is or includes a copy 7 | * or modification of this software and in all copies of the supporting 8 | * documentation for such software. 9 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 10 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE 11 | * ANY REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY 12 | * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 13 | */ 14 | #include 15 | #include "plan9.h" 16 | #include "fmt.h" 17 | #include "fmtdef.h" 18 | 19 | char* 20 | smprint(const char *fmt, ...) 21 | { 22 | va_list args; 23 | char *p; 24 | 25 | va_start(args, fmt); 26 | p = vsmprint(fmt, args); 27 | va_end(args); 28 | return p; 29 | } 30 | -------------------------------------------------------------------------------- /lib/libfmt/snprint.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson. 3 | * Copyright (c) 2002 by Lucent Technologies. 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose without fee is hereby granted, provided that this entire notice 6 | * is included in all copies of any software which is or includes a copy 7 | * or modification of this software and in all copies of the supporting 8 | * documentation for such software. 9 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 10 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE 11 | * ANY REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY 12 | * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 13 | */ 14 | #include 15 | #include "plan9.h" 16 | #include "fmt.h" 17 | #include "fmtdef.h" 18 | 19 | int 20 | snprint(char *buf, int len, const char *fmt, ...) 21 | { 22 | int n; 23 | va_list args; 24 | 25 | va_start(args, fmt); 26 | n = vsnprint(buf, len, fmt, args); 27 | va_end(args); 28 | return n; 29 | } 30 | 31 | -------------------------------------------------------------------------------- /lib/libfmt/test2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int 6 | main(int argc, char **argv) 7 | { 8 | print("%020.10d\n", 100); 9 | } 10 | -------------------------------------------------------------------------------- /lib/libfmt/test3.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | void 6 | test(char *fmt, ...) 7 | { 8 | va_list arg; 9 | char fmtbuf[100], stdbuf[100]; 10 | 11 | va_start(arg, fmt); 12 | vsnprint(fmtbuf, sizeof fmtbuf, fmt, arg); 13 | va_end(arg); 14 | 15 | va_start(arg, fmt); 16 | vsnprint(stdbuf, sizeof stdbuf, fmt, arg); 17 | va_end(arg); 18 | 19 | if(strcmp(fmtbuf, stdbuf) != 0) 20 | print("fmt %s: fmt=\"%s\" std=\"%s\"\n", fmt, fmtbuf, stdbuf); 21 | 22 | print("fmt %s: %s\n", fmt, fmtbuf); 23 | } 24 | 25 | 26 | int 27 | main(int argc, char *argv[]) 28 | { 29 | test("%f", 3.14159); 30 | test("%f", 3.14159e10); 31 | test("%f", 3.14159e-10); 32 | 33 | test("%e", 3.14159); 34 | test("%e", 3.14159e10); 35 | test("%e", 3.14159e-10); 36 | 37 | test("%g", 3.14159); 38 | test("%g", 3.14159e10); 39 | test("%g", 3.14159e-10); 40 | 41 | test("%g", 2e25); 42 | test("%.18g", 2e25); 43 | 44 | test("%2.18g", 1.0); 45 | test("%2.18f", 1.0); 46 | test("%f", 3.1415927/4); 47 | 48 | test("%20.10d", 12345); 49 | test("%0.10d", 12345); 50 | 51 | return 0; 52 | } 53 | -------------------------------------------------------------------------------- /lib/libfmt/vfprint.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson. 3 | * Copyright (c) 2002 by Lucent Technologies. 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose without fee is hereby granted, provided that this entire notice 6 | * is included in all copies of any software which is or includes a copy 7 | * or modification of this software and in all copies of the supporting 8 | * documentation for such software. 9 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 10 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE 11 | * ANY REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY 12 | * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 13 | */ 14 | #include 15 | #include "plan9.h" 16 | #include "fmt.h" 17 | #include "fmtdef.h" 18 | 19 | int 20 | vfprint(int fd, const char *fmt, va_list args) 21 | { 22 | Fmt f; 23 | char buf[256]; 24 | int n; 25 | 26 | fmtfdinit(&f, fd, buf, sizeof(buf)); 27 | va_copy(f.args,args); 28 | n = dofmt(&f, fmt); 29 | va_end(f.args); 30 | if(n > 0 && __fmtFdFlush(&f) == 0) 31 | return -1; 32 | return n; 33 | } 34 | -------------------------------------------------------------------------------- /lib/libfmt/vseprint.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson. 3 | * Copyright (c) 2002 by Lucent Technologies. 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose without fee is hereby granted, provided that this entire notice 6 | * is included in all copies of any software which is or includes a copy 7 | * or modification of this software and in all copies of the supporting 8 | * documentation for such software. 9 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 10 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE 11 | * ANY REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY 12 | * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 13 | */ 14 | #include 15 | #include "plan9.h" 16 | #include "fmt.h" 17 | #include "fmtdef.h" 18 | 19 | char* 20 | vseprint(char *buf, char *e, const char *fmt, va_list args) 21 | { 22 | Fmt f; 23 | 24 | if(e <= buf) 25 | return nil; 26 | f.runes = 0; 27 | f.start = buf; 28 | f.to = buf; 29 | f.stop = e - 1; 30 | f.flush = 0; 31 | f.farg = nil; 32 | f.nfmt = 0; 33 | va_copy(f.args,args); 34 | fmtlocaleinit(&f, nil, nil, nil); 35 | dofmt(&f, fmt); 36 | va_end(f.args); 37 | *(char*)f.to = '\0'; 38 | return (char*)f.to; 39 | } 40 | 41 | -------------------------------------------------------------------------------- /lib/libfmt/vsnprint.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson. 3 | * Copyright (c) 2002 by Lucent Technologies. 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose without fee is hereby granted, provided that this entire notice 6 | * is included in all copies of any software which is or includes a copy 7 | * or modification of this software and in all copies of the supporting 8 | * documentation for such software. 9 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 10 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE 11 | * ANY REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY 12 | * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 13 | */ 14 | #include 15 | #include 16 | #include "plan9.h" 17 | #include "fmt.h" 18 | #include "fmtdef.h" 19 | 20 | int 21 | vsnprint(char *buf, int len, const char *fmt, va_list args) 22 | { 23 | Fmt f; 24 | 25 | if(len <= 0) 26 | return -1; 27 | f.runes = 0; 28 | f.start = buf; 29 | f.to = buf; 30 | f.stop = buf + len - 1; 31 | f.flush = 0; 32 | f.farg = nil; 33 | f.nfmt = 0; 34 | va_copy(f.args,args); 35 | fmtlocaleinit(&f, nil, nil, nil); 36 | dofmt(&f, fmt); 37 | va_end(f.args); 38 | *(char*)f.to = '\0'; 39 | return (char*)f.to - buf; 40 | } 41 | -------------------------------------------------------------------------------- /lib/libregexp/Makefile: -------------------------------------------------------------------------------- 1 | ROOT= ../.. 2 | include $(ROOT)/mk/hdr.mk 3 | 4 | VERSION=2.0 5 | TARG=libregexp9 6 | 7 | OBJ=\ 8 | regcomp\ 9 | regerror\ 10 | regexec\ 11 | regsub\ 12 | regaux\ 13 | rregexec\ 14 | rregsub 15 | 16 | include $(ROOT)/mk/lib.mk 17 | 18 | -------------------------------------------------------------------------------- /lib/libregexp/NOTICE: -------------------------------------------------------------------------------- 1 | This is a Unix port of the Plan 9 regular expression library, by Rob Pike. 2 | Please send comments about the packaging to Russ Cox . 3 | 4 | Copyright © 2021 Plan 9 Foundation 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /lib/libregexp/README: -------------------------------------------------------------------------------- 1 | This software was packaged for Unix by Russ Cox. 2 | Please send comments to rsc@swtch.com. 3 | 4 | http://swtch.com/plan9port/unix 5 | 6 | -------------------------------------------------------------------------------- /lib/libregexp/regerror.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | void 6 | regerror(char *s) 7 | { 8 | char buf[132]; 9 | 10 | strcpy(buf, "regerror: "); 11 | strcat(buf, s); 12 | strcat(buf, "\n"); 13 | write(2, buf, strlen(buf)); 14 | exits("regerr"); 15 | } 16 | -------------------------------------------------------------------------------- /lib/libregexp/test.c: -------------------------------------------------------------------------------- 1 | #include "plan9.h" 2 | #include 3 | 4 | struct x 5 | { 6 | char *re; 7 | char *s; 8 | Reprog *p; 9 | }; 10 | 11 | struct x t[] = { 12 | { "^[^!@]+$", "/bin/upas/aliasmail '&'", 0 }, 13 | { "^local!(.*)$", "/mail/box/\\1/mbox", 0 }, 14 | { "^plan9!(.*)$", "\\1", 0 }, 15 | { "^helix!(.*)$", "\\1", 0 }, 16 | { "^([^!]+)@([^!@]+)$", "\\2!\\1", 0 }, 17 | { "^(uk\\.[^!]*)(!.*)$", "/bin/upas/uk2uk '\\1' '\\2'", 0 }, 18 | { "^[^!]*\\.[^!]*!.*$", "inet!&", 0 }, 19 | { "^\xE2\x98\xBA$", "smiley", 0 }, 20 | { "^(coma|research|pipe|pyxis|inet|hunny|gauss)!(.*)$", "/mail/lib/qmail '\\s' 'net!\\1' '\\2'", 0 }, 21 | { "^.*$", "/mail/lib/qmail '\\s' 'net!research' '&'", 0 }, 22 | { 0, 0, 0 }, 23 | }; 24 | 25 | main(int ac, char **av) 26 | { 27 | Resub rs[10]; 28 | char dst[128]; 29 | int n; 30 | struct x *tp; 31 | 32 | for(tp = t; tp->re; tp++) 33 | tp->p = regcomp(tp->re); 34 | 35 | 36 | for(tp = t; tp->re; tp++){ 37 | print("%s VIA %s", av[1], tp->re); 38 | memset(rs, 0, sizeof rs); 39 | if(regexec(tp->p, av[1], rs, 10)){ 40 | regsub(tp->s, dst, sizeof dst, rs, 10); 41 | print(" sub %s -> %s", tp->s, dst); 42 | } 43 | print("\n"); 44 | } 45 | exit(0); 46 | } 47 | -------------------------------------------------------------------------------- /lib/libregexp/test2.c: -------------------------------------------------------------------------------- 1 | #include "plan9.h" 2 | #include 3 | 4 | 5 | main(int ac, char **av) 6 | { 7 | Resub rs[10]; 8 | Reprog *p; 9 | char *s; 10 | int i; 11 | 12 | p = regcomp("[^a-z]"); 13 | s = "\n"; 14 | if(regexec(p, s, rs, 10)) 15 | print("%s %lux %lux %lux\n", s, s, rs[0].sp, rs[0].ep); 16 | s = "0"; 17 | if(regexec(p, s, rs, 10)) 18 | print("%s %lux %lux %lux\n", s, s, rs[0].sp, rs[0].ep); 19 | exit(0); 20 | } 21 | -------------------------------------------------------------------------------- /lib/libstuff/buffer.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2008-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | 5 | char buffer[8092]; 6 | char* _buffer; 7 | char* const _buf_end = buffer + sizeof buffer; 8 | 9 | -------------------------------------------------------------------------------- /lib/libstuff/client_readconfig.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2009-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | void 11 | client_readconfig(CTuple *norm, CTuple *focus, Font **font) { 12 | 13 | if(norm) 14 | loadcolor(norm, readctl("/ctl", "normcolors "), nil); 15 | if(focus) 16 | loadcolor(focus, readctl("/ctl", "focuscolors "), nil); 17 | *font = loadfont(readctl("/ctl", "font ")); 18 | if(!*font) 19 | fatal("Can't load font %q", readctl("/ctl", "font ")); 20 | sscanf(readctl("/ctl", "fontpad "), "%d %d %d %d", 21 | &(*font)->pad.min.x, &(*font)->pad.max.x, 22 | &(*font)->pad.min.x, &(*font)->pad.max.y); 23 | } 24 | 25 | -------------------------------------------------------------------------------- /lib/libstuff/event/buttonpress.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2006-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "event.h" 5 | 6 | void 7 | event_buttonpress(XButtonPressedEvent *ev) { 8 | Window *w; 9 | 10 | if((w = findwin(ev->window))) 11 | event_handle(w, bdown, ev); 12 | else 13 | XAllowEvents(display, ReplayPointer, ev->time); 14 | } 15 | -------------------------------------------------------------------------------- /lib/libstuff/event/buttonrelease.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2006-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "event.h" 5 | 6 | void 7 | event_buttonrelease(XButtonPressedEvent *ev) { 8 | Window *w; 9 | 10 | if((w = findwin(ev->window))) 11 | event_handle(w, bup, ev); 12 | } 13 | -------------------------------------------------------------------------------- /lib/libstuff/event/clientmessage.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2006-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "event.h" 5 | 6 | void 7 | event_clientmessage(XClientMessageEvent *ev) { 8 | Window *w; 9 | 10 | if((w = findwin(ev->window))) 11 | event_handle(w, message, ev); 12 | } 13 | -------------------------------------------------------------------------------- /lib/libstuff/event/configurenotify.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2006-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "event.h" 5 | 6 | void 7 | event_configurenotify(XConfigureEvent *ev) { 8 | Window *w; 9 | 10 | if(!ev->send_event) 11 | event_lastconfigure = ev->serial; 12 | if((w = findwin(ev->window))) 13 | event_handle(w, config, ev); 14 | } 15 | -------------------------------------------------------------------------------- /lib/libstuff/event/configurerequest.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2006-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "event.h" 5 | 6 | void 7 | event_configurerequest(XConfigureRequestEvent *ev) { 8 | XWindowChanges wc; 9 | Window *w; 10 | 11 | if((w = findwin(ev->window))) 12 | event_handle(w, configreq, ev); 13 | else{ 14 | wc.x = ev->x; 15 | wc.y = ev->y; 16 | wc.width = ev->width; 17 | wc.height = ev->height; 18 | wc.border_width = ev->border_width; 19 | wc.sibling = ev->above; 20 | wc.stack_mode = ev->detail; 21 | XConfigureWindow(display, ev->window, ev->value_mask, &wc); 22 | } 23 | } 24 | 25 | -------------------------------------------------------------------------------- /lib/libstuff/event/destroynotify.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2006-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "event.h" 5 | 6 | void 7 | event_destroynotify(XDestroyWindowEvent *ev) { 8 | Window *w; 9 | 10 | if(!ev->send_event) 11 | event_lastconfigure = ev->serial; 12 | if((w = findwin(ev->window))) 13 | event_handle(w, destroy, ev); 14 | } 15 | -------------------------------------------------------------------------------- /lib/libstuff/event/enternotify.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2006-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "event.h" 5 | 6 | void 7 | event_enternotify(XCrossingEvent *ev) { 8 | Window *w; 9 | 10 | if(!ev->send_event) 11 | event_xtime = ev->time; 12 | if(ev->mode != NotifyNormal) 13 | return; 14 | 15 | if((w = findwin(ev->window))) 16 | event_handle(w, enter, ev); 17 | } 18 | -------------------------------------------------------------------------------- /lib/libstuff/event/event.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | typedef void (*EventHandler)(XEvent*); 4 | 5 | #define handle(w, fn, ev) \ 6 | BLOCK(if((w)->handler->fn) (w)->handler->fn((w), ev)) 7 | 8 | extern EventHandler event_handler[LASTEvent]; 9 | 10 | -------------------------------------------------------------------------------- /lib/libstuff/event/expose.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2006-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "event.h" 5 | 6 | void 7 | event_expose(XExposeEvent *ev) { 8 | Window *w; 9 | 10 | if(ev->count == 0 && (w = findwin(ev->window))) 11 | event_handle(w, expose, ev); 12 | } 13 | -------------------------------------------------------------------------------- /lib/libstuff/event/focusin.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2006-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "event.h" 5 | 6 | void 7 | event_focusin(XFocusChangeEvent *ev) { 8 | Window *w; 9 | 10 | /* Yes, we're focusing in on nothing, here. */ 11 | if(ev->detail == NotifyDetailNone) { 12 | /* FIXME: Do something. */ 13 | return; 14 | } 15 | 16 | if(!((ev->detail == NotifyNonlinear) 17 | ||(ev->detail == NotifyNonlinearVirtual) 18 | ||(ev->detail == NotifyVirtual) 19 | ||(ev->detail == NotifyInferior) 20 | ||(ev->detail == NotifyAncestor))) 21 | return; 22 | if((ev->mode == NotifyWhileGrabbed)) 23 | return; 24 | 25 | if((w = findwin(ev->window))) 26 | event_handle(w, focusin, ev); 27 | } 28 | -------------------------------------------------------------------------------- /lib/libstuff/event/focusout.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2006-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "event.h" 5 | 6 | void 7 | event_focusout(XFocusChangeEvent *ev) { 8 | Window *w; 9 | 10 | if(!((ev->detail == NotifyNonlinear) 11 | ||(ev->detail == NotifyNonlinearVirtual) 12 | ||(ev->detail == NotifyVirtual) 13 | ||(ev->detail == NotifyInferior) 14 | ||(ev->detail == NotifyAncestor))) 15 | return; 16 | 17 | if((w = findwin(ev->window))) 18 | event_handle(w, focusout, ev); 19 | } 20 | -------------------------------------------------------------------------------- /lib/libstuff/event/ixp.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include 5 | #include "event.h" 6 | 7 | void 8 | event_preselect(IxpServer *s) { 9 | USED(s); 10 | event_check(); 11 | XFlush(display); 12 | } 13 | 14 | void 15 | event_fdready(IxpConn *c) { 16 | USED(c); 17 | event_check(); 18 | } 19 | 20 | void 21 | event_fdclosed(IxpConn *c) { 22 | 23 | c->srv->running = false; 24 | } 25 | -------------------------------------------------------------------------------- /lib/libstuff/event/keypress.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2006-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "event.h" 5 | 6 | void 7 | event_keypress(XKeyEvent *ev) { 8 | Window *w; 9 | 10 | if(!ev->send_event) 11 | event_xtime = ev->time; 12 | if((w = findwin(ev->window))) 13 | event_handle(w, kdown, ev); 14 | } 15 | -------------------------------------------------------------------------------- /lib/libstuff/event/keyrelease.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2006-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "event.h" 5 | 6 | void 7 | event_keyrelease(XKeyEvent *ev) { 8 | Window *w; 9 | 10 | if(!ev->send_event) 11 | event_xtime = ev->time; 12 | if((w = findwin(ev->window))) 13 | event_handle(w, kup, ev); 14 | } 15 | -------------------------------------------------------------------------------- /lib/libstuff/event/leavenotify.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2006-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "event.h" 5 | 6 | void 7 | event_leavenotify(XCrossingEvent *ev) { 8 | Window *w; 9 | 10 | if(!ev->send_event) 11 | event_xtime = ev->time; 12 | if((w = findwin(ev->window))) 13 | event_handle(w, leave, ev); 14 | } 15 | -------------------------------------------------------------------------------- /lib/libstuff/event/mapnotify.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2006-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "event.h" 5 | 6 | void 7 | event_mapnotify(XMapEvent *ev) { 8 | Window *w; 9 | 10 | if(!ev->send_event) 11 | event_lastconfigure = ev->serial; 12 | if((w = findwin(ev->event))) 13 | event_handle(w, map, ev); 14 | if(ev->send_event && (w = findwin(ev->event))) 15 | event_handle(w, map, ev); 16 | } 17 | -------------------------------------------------------------------------------- /lib/libstuff/event/mappingnotify.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2006-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "event.h" 5 | 6 | void 7 | event_mappingnotify(XMappingEvent *ev) { 8 | 9 | /* Why do you need me to tell you this? */ 10 | XRefreshKeyboardMapping(ev); 11 | } 12 | -------------------------------------------------------------------------------- /lib/libstuff/event/maprequest.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2006-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "event.h" 5 | 6 | void 7 | event_maprequest(XMapRequestEvent *ev) { 8 | Window *w; 9 | 10 | if((w = findwin(ev->parent))) 11 | event_handle(w, mapreq, ev); 12 | } 13 | -------------------------------------------------------------------------------- /lib/libstuff/event/motionnotify.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2006-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "event.h" 5 | 6 | void 7 | event_motionnotify(XMotionEvent *ev) { 8 | Window *w; 9 | 10 | if(!ev->send_event) 11 | event_xtime = ev->time; 12 | if((w = findwin(ev->window))) 13 | event_handle(w, motion, ev); 14 | } 15 | -------------------------------------------------------------------------------- /lib/libstuff/event/propertynotify.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2006-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "event.h" 5 | 6 | void 7 | event_propertynotify(XPropertyEvent *ev) { 8 | Window *w; 9 | 10 | if(!ev->send_event) 11 | event_xtime = ev->time; 12 | if((w = findwin(ev->window))) 13 | event_handle(w, property, ev); 14 | } 15 | -------------------------------------------------------------------------------- /lib/libstuff/event/reparentnotify.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2006-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "event.h" 5 | 6 | void 7 | event_reparentnotify(XReparentEvent *ev) { 8 | Window *target, *w; 9 | 10 | if(!ev->send_event) 11 | event_lastconfigure = ev->serial; 12 | w = nil; 13 | if((target = findwin(ev->window)) && (w = findwin(ev->parent))) 14 | target->parent = w; 15 | if((w = findwin(ev->event))) 16 | event_handle(w, reparent, ev); 17 | if(ev->send_event && target) 18 | event_handle(target, reparent, ev); 19 | } 20 | -------------------------------------------------------------------------------- /lib/libstuff/event/selection.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "event.h" 5 | 6 | void 7 | event_selection(XSelectionEvent *ev) { 8 | Window *w; 9 | 10 | if(!ev->send_event) 11 | event_xtime = ev->time; 12 | if((w = findwin(ev->requestor))) 13 | event_handle(w, selection, ev); 14 | } 15 | 16 | -------------------------------------------------------------------------------- /lib/libstuff/event/selectionclear.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "event.h" 5 | 6 | void 7 | event_selectionclear(XSelectionClearEvent *ev) { 8 | Window *w; 9 | 10 | if(!ev->send_event) 11 | event_xtime = ev->time; 12 | if((w = findwin(ev->window))) 13 | event_handle(w, selectionclear, ev); 14 | } 15 | -------------------------------------------------------------------------------- /lib/libstuff/event/selectionrequest.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "event.h" 5 | 6 | void 7 | event_selectionrequest(XSelectionRequestEvent *ev) { 8 | Window *w; 9 | 10 | if(!ev->send_event) 11 | event_xtime = ev->time; 12 | if((w = findwin(ev->owner))) 13 | event_handle(w, selectionrequest, ev); 14 | } 15 | 16 | -------------------------------------------------------------------------------- /lib/libstuff/event/unmapnotify.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2006-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "event.h" 5 | 6 | void 7 | event_unmapnotify(XUnmapEvent *ev) { 8 | Window *w; 9 | 10 | if(!ev->send_event) 11 | event_lastconfigure = ev->serial; 12 | if((w = findwin(ev->window))) { 13 | if(!ev->send_event) 14 | w->mapped = false; 15 | if(!ev->send_event && ev->event == ev->window) 16 | w->unmapped--; 17 | if(ev->send_event && ev->event != ev->window) 18 | event_handle(w, unmap, ev); 19 | } 20 | if((w = findwin(ev->event))) 21 | event_handle(w, unmap, ev); 22 | } 23 | -------------------------------------------------------------------------------- /lib/libstuff/event/xtime.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2006-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include 5 | 6 | static int 7 | findtime(Display *d, XEvent *e, XPointer v) { 8 | Window *w; 9 | 10 | w = (Window*)v; 11 | if(e->type == PropertyNotify && e->xproperty.window == w->xid) { 12 | event_xtime = e->xproperty.time; 13 | return true; 14 | } 15 | return false; 16 | } 17 | 18 | long 19 | event_updatextime(void) { 20 | Window *w; 21 | WinAttr wa; 22 | XEvent e; 23 | long l; 24 | 25 | w = createwindow(&scr.root, Rect(0, 0, 1, 1), 0, InputOnly, &wa, 0); 26 | 27 | XSelectInput(display, w->xid, PropertyChangeMask); 28 | changeprop_long(w, "ATOM", "ATOM", &l, 0); 29 | XIfEvent(display, &e, findtime, (void*)w); 30 | 31 | destroywindow(w); 32 | return event_xtime; 33 | } 34 | 35 | -------------------------------------------------------------------------------- /lib/libstuff/fmt/blprint.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2010 Kris Maglione 2 | * Copyright ©2002 by Lucent Technologies. 3 | * See LICENSE file for license details. 4 | */ 5 | #include "fmtdef.h" 6 | #include 7 | 8 | int 9 | Blprint(Biobuf *bp, const char *fmt, ...) 10 | { 11 | va_list arg; 12 | int n; 13 | 14 | va_start(arg, fmt); 15 | n = Bvlprint(bp, fmt, arg); 16 | va_end(arg); 17 | return n; 18 | } 19 | 20 | -------------------------------------------------------------------------------- /lib/libstuff/fmt/bvlprint.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2010 Kris Maglione 2 | * Copyright ©2002 by Lucent Technologies. 3 | * See LICENSE file for license details. 4 | */ 5 | #include "fmtdef.h" 6 | #include 7 | 8 | static int 9 | fmtBlflush(Fmt *f) 10 | { 11 | mbstate_t state; 12 | Biobuf *bp; 13 | Rune *rp, *rend; 14 | int res; 15 | 16 | bp = f->farg; 17 | rend = f->to; 18 | state = (mbstate_t){0}; 19 | for(rp=(Rune*)f->start; rp < rend; rp++) { 20 | if(MB_LEN_MAX + bp->ocount > 0 && Bflush(bp) < 0) 21 | return 0; 22 | 23 | res = wcrtomb((char*)bp->ebuf + bp->ocount, *rp, &state); 24 | if(res == -1) 25 | Bputc(bp, '?'); 26 | else 27 | bp->ocount += res; 28 | } 29 | f->to = f->start; 30 | return 1; 31 | } 32 | 33 | int 34 | Bvlprint(Biobuf *bp, const char *fmt, va_list args) 35 | { 36 | Fmt f; 37 | Rune buf[256]; 38 | int res; 39 | 40 | if(utf8locale()) 41 | return Bvprint(bp, fmt, args); 42 | 43 | f.runes = 1; 44 | f.start = (char*)buf; 45 | f.to = (char*)buf; 46 | f.stop = (char*)(buf + nelem(buf) - 1); 47 | f.flush = fmtBlflush; 48 | f.farg = bp; 49 | f.nfmt = 0; 50 | 51 | va_copy(f.args, args); 52 | res = dofmt(&f, fmt); 53 | va_end(f.args); 54 | if(res > 0 && fmtBlflush(&f) == 0) 55 | return -1; 56 | return res; 57 | } 58 | 59 | -------------------------------------------------------------------------------- /lib/libstuff/fmt/fmtbuf.c: -------------------------------------------------------------------------------- 1 | #include "fmtdef.h" 2 | 3 | Fmt 4 | fmtbuf(char *buf, int len) { 5 | Fmt f; 6 | 7 | f.runes = 0; 8 | f.start = buf; 9 | f.to = buf; 10 | f.stop = buf + len - 1; 11 | f.flush = 0; 12 | f.farg = nil; 13 | f.nfmt = 0; 14 | return f; 15 | } 16 | -------------------------------------------------------------------------------- /lib/libstuff/fmt/fmtdef.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | extern void* __fmtflush(Fmt *f, void *t, int len); 8 | extern int __fmtpad(Fmt *f, int n); 9 | extern int __rfmtpad(Fmt *f, int n); 10 | 11 | -------------------------------------------------------------------------------- /lib/libstuff/fmt/localelen.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2010 Kris Maglione 2 | * Copyright ©2002 by Lucent Technologies. 3 | * See LICENSE file for license details. 4 | */ 5 | #include "fmtdef.h" 6 | 7 | int 8 | localelen(char *str, char *end) { 9 | mbstate_t state; 10 | size_t n, res; 11 | 12 | if(utf8locale()) { 13 | if(end) 14 | return utfnlen(str, end - str); 15 | return utflen(str); 16 | } 17 | 18 | state = (mbstate_t){0}; 19 | n = 0; 20 | for(n=0;;) 21 | switch((res = mbrtowc(nil, str, end ? end - str : MB_LEN_MAX, &state))) { 22 | case -1: 23 | return -1; 24 | case 0: 25 | case -2: 26 | return n; 27 | default: 28 | n++; 29 | str += res; 30 | } 31 | return n; /* Not reached. */ 32 | } 33 | 34 | -------------------------------------------------------------------------------- /lib/libstuff/fmt/lprint.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2010 Kris Maglione 2 | * Copyright ©2002 by Lucent Technologies. 3 | * See LICENSE file for license details. 4 | */ 5 | #include "fmtdef.h" 6 | 7 | int 8 | lprint(int fd, const char *fmt, ...) { 9 | va_list ap; 10 | int res; 11 | 12 | va_start(ap, fmt); 13 | res = vlprint(fd, fmt, ap); 14 | va_end(ap); 15 | return res; 16 | } 17 | 18 | -------------------------------------------------------------------------------- /lib/libstuff/geom/get_sticky.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2006-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include 5 | 6 | Align 7 | get_sticky(Rectangle src, Rectangle dst) { 8 | Align corner; 9 | 10 | corner = 0; 11 | if(src.min.x != dst.min.x 12 | && src.max.x == dst.max.x) 13 | corner |= East; 14 | else 15 | corner |= West; 16 | 17 | if(src.min.y != dst.min.y 18 | && src.max.y == dst.max.y) 19 | corner |= South; 20 | else 21 | corner |= North; 22 | 23 | return corner; 24 | } 25 | -------------------------------------------------------------------------------- /lib/libstuff/geom/quadrant.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2006-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include 5 | 6 | Align 7 | quadrant(Rectangle r, Point pt) { 8 | Align ret; 9 | 10 | pt = subpt(pt, r.min); 11 | ret = East * (pt.x >= Dx(r) * .7) 12 | | West * (pt.x <= Dx(r) * .3) 13 | | South * (pt.y >= Dy(r) * .7) 14 | | North * (pt.y <= Dy(r) * .3); 15 | 16 | return ret; 17 | } 18 | -------------------------------------------------------------------------------- /lib/libstuff/geom/rect_contains_p.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2006-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include 5 | 6 | bool 7 | rect_contains_p(Rectangle r, Rectangle r2) { 8 | return r2.min.x >= r.min.x 9 | && r2.max.x <= r.max.x 10 | && r2.min.y >= r.min.y 11 | && r2.max.y <= r.max.y; 12 | } 13 | -------------------------------------------------------------------------------- /lib/libstuff/geom/rect_haspoint_p.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2006-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include 5 | 6 | bool 7 | rect_haspoint_p(Rectangle r, Point pt) { 8 | return (pt.x >= r.min.x) && (pt.x < r.max.x) 9 | && (pt.y >= r.min.y) && (pt.y < r.max.y); 10 | } 11 | -------------------------------------------------------------------------------- /lib/libstuff/geom/rect_intersect_p.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2006-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include 5 | 6 | bool 7 | rect_intersect_p(Rectangle r, Rectangle r2) { 8 | return r.min.x <= r2.max.x 9 | && r.max.x >= r2.min.x 10 | && r.min.y <= r2.max.y 11 | && r.max.y >= r2.min.y; 12 | } 13 | -------------------------------------------------------------------------------- /lib/libstuff/geom/rect_intersection.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2006-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include 5 | #include 6 | 7 | Rectangle 8 | rect_intersection(Rectangle r, Rectangle r2) { 9 | Rectangle ret; 10 | 11 | /* ret != canonrect(ret) ≡ no intersection. */ 12 | ret.min.x = max(r.min.x, r2.min.x); 13 | ret.max.x = min(r.max.x, r2.max.x); 14 | ret.min.y = max(r.min.y, r2.min.y); 15 | ret.max.y = min(r.max.y, r2.max.y); 16 | return ret; 17 | } 18 | -------------------------------------------------------------------------------- /lib/libstuff/init_screens.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | 5 | void init_screens(void); 6 | void 7 | init_screens(void) { 8 | } 9 | 10 | -------------------------------------------------------------------------------- /lib/libstuff/util/_die.c: -------------------------------------------------------------------------------- 1 | /* Written by Kris Maglione */ 2 | /* Public domain */ 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include "util.h" 8 | 9 | void 10 | _die(char *file, int line, char *msg, ...) { 11 | va_list ap; 12 | 13 | va_start(ap, msg); 14 | fprint(2, "%s: dieing at %s:%d: %s\n", 15 | argv0, file, line, 16 | vsxprint(msg, ap)); 17 | va_end(ap); 18 | 19 | kill(getpid(), SIGABRT); 20 | abort(); /* Adds too many frames: 21 | * _die() 22 | * abort() 23 | * raise(SIGABRT) 24 | * kill(getpid(), SIGABRT) 25 | */ 26 | } 27 | -------------------------------------------------------------------------------- /lib/libstuff/util/closeexec.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2008-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include 5 | #include 6 | #include "util.h" 7 | 8 | void 9 | closeexec(int fd) { 10 | if(fcntl(fd, F_SETFD, FD_CLOEXEC) == -1) 11 | fatal("can't set %d close on exec: %r", fd); 12 | } 13 | -------------------------------------------------------------------------------- /lib/libstuff/util/comm.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2008-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include 5 | #include "util.h" 6 | #include 7 | 8 | 9 | char** 10 | comm(int cols, char **toka, char **tokb) { 11 | Vector_ptr vec; 12 | char **ret; 13 | int cmp; 14 | 15 | vector_pinit(&vec); 16 | while(*toka || *tokb) { 17 | if(!*toka) 18 | cmp = 1; 19 | else if(!*tokb) 20 | cmp = -1; 21 | else 22 | cmp = strcmp(*toka, *tokb); 23 | if(cmp < 0) { 24 | if(cols & CLeft) 25 | vector_ppush(&vec, *toka); 26 | toka++; 27 | }else if(cmp > 0) { 28 | if(cols & CRight) 29 | vector_ppush(&vec, *tokb); 30 | tokb++; 31 | }else { 32 | if(cols & CCenter) 33 | vector_ppush(&vec, *toka); 34 | toka++; 35 | tokb++; 36 | } 37 | } 38 | vector_ppush(&vec, nil); 39 | ret = strlistdup((char**)vec.ary); 40 | free(vec.ary); 41 | return ret; 42 | } 43 | -------------------------------------------------------------------------------- /lib/libstuff/util/doublefork.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2008-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include 5 | #include 6 | #include "util.h" 7 | 8 | int 9 | doublefork(void) { 10 | pid_t pid; 11 | int status; 12 | 13 | switch(pid=fork()) { 14 | case -1: 15 | fatal("Can't fork(): %r"); 16 | case 0: 17 | switch(pid=fork()) { 18 | case -1: 19 | fatal("Can't fork(): %r"); 20 | case 0: 21 | return 0; 22 | default: 23 | exit(0); 24 | } 25 | default: 26 | waitpid(pid, &status, 0); 27 | return pid; 28 | } 29 | /* NOTREACHED */ 30 | } 31 | -------------------------------------------------------------------------------- /lib/libstuff/util/emalloc.c: -------------------------------------------------------------------------------- 1 | /* Written by Kris Maglione */ 2 | /* Public domain */ 3 | #include "util.h" 4 | 5 | void * 6 | emalloc(uint size) { 7 | void *ret = malloc(size); 8 | if(!ret) 9 | mfatal("malloc", size); 10 | return ret; 11 | } 12 | -------------------------------------------------------------------------------- /lib/libstuff/util/emallocz.c: -------------------------------------------------------------------------------- 1 | /* Written by Kris Maglione */ 2 | /* Public domain */ 3 | #include 4 | #include "util.h" 5 | 6 | void* 7 | emallocz(uint size) { 8 | void *ret = emalloc(size); 9 | memset(ret, 0, size); 10 | return ret; 11 | } 12 | -------------------------------------------------------------------------------- /lib/libstuff/util/erealloc.c: -------------------------------------------------------------------------------- 1 | /* Written by Kris Maglione */ 2 | /* Public domain */ 3 | #include "util.h" 4 | 5 | void * 6 | erealloc(void *ptr, uint size) { 7 | void *ret = realloc(ptr, size); 8 | if(!ret) 9 | mfatal("realloc", size); 10 | return ret; 11 | } 12 | -------------------------------------------------------------------------------- /lib/libstuff/util/estrdup.c: -------------------------------------------------------------------------------- 1 | /* Written by Kris Maglione */ 2 | /* Public domain */ 3 | #include 4 | #include "util.h" 5 | 6 | char* 7 | estrdup(const char *str) { 8 | void *ret = strdup(str); 9 | if(!ret) 10 | mfatal("strdup", strlen(str)); 11 | return ret; 12 | } 13 | -------------------------------------------------------------------------------- /lib/libstuff/util/estrndup.c: -------------------------------------------------------------------------------- 1 | /* Written by Kris Maglione */ 2 | /* Public domain */ 3 | #include 4 | #include "util.h" 5 | 6 | char* 7 | estrndup(const char *str, uint len) { 8 | char *ret; 9 | 10 | len = min(len, strlen(str)); 11 | ret = emalloc(len + 1); 12 | memcpy(ret, str, len); 13 | ret[len] = '\0'; 14 | return ret; 15 | } 16 | -------------------------------------------------------------------------------- /lib/libstuff/util/fatal.c: -------------------------------------------------------------------------------- 1 | /* Written by Kris Maglione */ 2 | /* Public domain */ 3 | #include 4 | #include "util.h" 5 | 6 | typedef struct VFmt VFmt; 7 | struct VFmt { 8 | const char *fmt; 9 | va_list args; 10 | }; 11 | 12 | #ifdef VARARGCK 13 | # pragma varargck type "V" VFmt* 14 | #endif 15 | 16 | static int 17 | Vfmt(Fmt *f) { 18 | VFmt *vf; 19 | int i; 20 | 21 | vf = va_arg(f->args, VFmt*); 22 | i = fmtvprint(f, vf->fmt, vf->args); 23 | return i; 24 | } 25 | 26 | void 27 | fatal(const char *fmt, ...) { 28 | VFmt fp; 29 | 30 | fmtinstall('V', Vfmt); 31 | fmtinstall('', Vfmt); 32 | 33 | fp.fmt = fmt; 34 | va_start(fp.args, fmt); 35 | fprint(2, "%s: fatal: %V\n", argv0, &fp); 36 | va_end(fp.args); 37 | 38 | exit(1); 39 | } 40 | -------------------------------------------------------------------------------- /lib/libstuff/util/freelater.c: -------------------------------------------------------------------------------- 1 | /* Written by Kris Maglione */ 2 | /* Public domain */ 3 | #include "util.h" 4 | 5 | void* 6 | freelater(void *p) { 7 | static char* obj[16]; 8 | static long nobj; 9 | int id; 10 | 11 | id = nobj++ % nelem(obj); 12 | free(obj[id]); 13 | obj[id] = p; 14 | return p; 15 | } 16 | -------------------------------------------------------------------------------- /lib/libstuff/util/getbase.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2008-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include 5 | #include 6 | #include 7 | 8 | #define strbcmp(str, const) (strncmp((str), (const), sizeof(const)-1)) 9 | int 10 | getbase(const char **s, long *sign) { 11 | const char *p; 12 | int ret; 13 | 14 | ret = 10; 15 | *sign = 1; 16 | if(**s == '-') { 17 | *sign = -1; 18 | *s += 1; 19 | }else if(**s == '+') 20 | *s += 1; 21 | 22 | p = *s; 23 | if(!strbcmp(p, "0x")) { 24 | *s += 2; 25 | ret = 16; 26 | } 27 | else if(isdigit(p[0])) { 28 | if(p[1] == 'r') { 29 | *s += 2; 30 | ret = p[0] - '0'; 31 | } 32 | else if(isdigit(p[1]) && p[2] == 'r') { 33 | *s += 3; 34 | ret = 10*(p[0]-'0') + (p[1]-'0'); 35 | } 36 | } 37 | else if(p[0] == '0') { 38 | ret = 8; 39 | } 40 | if(ret != 10 && (**s == '-' || **s == '+')) 41 | *sign = 0; 42 | return ret; 43 | } 44 | -------------------------------------------------------------------------------- /lib/libstuff/util/getint.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2008-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include 5 | 6 | bool 7 | getint(const char *s, int *ret) { 8 | long l; 9 | bool res; 10 | 11 | res = getlong(s, &l); 12 | *ret = l; 13 | return res; 14 | } 15 | -------------------------------------------------------------------------------- /lib/libstuff/util/getlong.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2008-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include 5 | #include 6 | 7 | bool 8 | getlong(const char *s, long *ret) { 9 | const char *end; 10 | char *rend; 11 | int base; 12 | long sign; 13 | 14 | if(s == nil) 15 | return false; 16 | end = s+strlen(s); 17 | base = getbase(&s, &sign); 18 | if(sign == 0) 19 | return false; 20 | 21 | *ret = sign * strtol(s, &rend, base); 22 | return (end == rend); 23 | } 24 | -------------------------------------------------------------------------------- /lib/libstuff/util/getulong.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2008-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include 5 | #include 6 | 7 | bool 8 | getulong(const char *s, ulong *ret) { 9 | const char *end; 10 | char *rend; 11 | int base; 12 | long sign; 13 | 14 | if(s == nil) 15 | return false; 16 | end = s+strlen(s); 17 | base = getbase(&s, &sign); 18 | if(sign < 1) 19 | return false; 20 | 21 | *ret = strtoul(s, &rend, base); 22 | return (end == rend); 23 | } 24 | -------------------------------------------------------------------------------- /lib/libstuff/util/grep.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2008-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "util.h" 5 | 6 | 7 | void 8 | grep(char **list, Reprog *re, int flags) { 9 | char **p, **q; 10 | int res; 11 | 12 | q = list; 13 | for(p=q; *p; p++) { 14 | res = 0; 15 | if(re) 16 | res = regexec(re, *p, nil, 0); 17 | if(res && !(flags & GInvert) 18 | || !res && (flags & GInvert)) 19 | *q++ = *p; 20 | } 21 | *q = nil; 22 | } 23 | -------------------------------------------------------------------------------- /lib/libstuff/util/join.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2008-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include 5 | #include "util.h" 6 | 7 | char* 8 | join(char **list, char *sep, Fmt *f) { 9 | Fmt fmt; 10 | char **p; 11 | 12 | if(f == nil) { 13 | f = &fmt; 14 | if(fmtstrinit(f) < 0) 15 | abort(); 16 | } 17 | 18 | for(p=list; *p; p++) { 19 | if(p != list) 20 | fmtstrcpy(f, sep); 21 | fmtstrcpy(f, *p); 22 | } 23 | 24 | if(f != &fmt) 25 | return nil; 26 | return fmtstrflush(f); 27 | } 28 | -------------------------------------------------------------------------------- /lib/libstuff/util/max.c: -------------------------------------------------------------------------------- 1 | /* Written by Kris Maglione */ 2 | /* Public domain */ 3 | #include "util.h" 4 | 5 | int 6 | max(int a, int b) { 7 | if(a > b) 8 | return a; 9 | return b; 10 | } 11 | -------------------------------------------------------------------------------- /lib/libstuff/util/mfatal.c: -------------------------------------------------------------------------------- 1 | /* Written by Kris Maglione */ 2 | /* Public domain */ 3 | #include 4 | #include 5 | #include "util.h" 6 | 7 | /* Can't malloc */ 8 | void 9 | mfatal(char *name, uint size) { 10 | const char 11 | couldnot[] = ": fatal: Could not ", 12 | paren[] = "() ", 13 | bytes[] = " bytes\n"; 14 | char buf[1024]; 15 | char sizestr[8]; 16 | int i; 17 | 18 | i = sizeof sizestr; 19 | do { 20 | sizestr[--i] = '0' + (size%10); 21 | size /= 10; 22 | } while(size > 0); 23 | 24 | strlcat(buf, argv0, sizeof buf); 25 | strlcat(buf, couldnot, sizeof buf); 26 | strlcat(buf, name, sizeof buf); 27 | strlcat(buf, paren, sizeof buf); 28 | strlcat(buf, sizestr+i, sizeof buf); 29 | strlcat(buf, bytes, sizeof buf); 30 | write(2, buf, strlen(buf)); 31 | 32 | exit(1); 33 | } 34 | -------------------------------------------------------------------------------- /lib/libstuff/util/min.c: -------------------------------------------------------------------------------- 1 | /* Written by Kris Maglione */ 2 | /* Public domain */ 3 | #include "util.h" 4 | 5 | int 6 | min(int a, int b) { 7 | if(a < b) 8 | return a; 9 | return b; 10 | } 11 | -------------------------------------------------------------------------------- /lib/libstuff/util/nsec.c: -------------------------------------------------------------------------------- 1 | /* Written by Kris Maglione */ 2 | /* Public domain */ 3 | #include "util.h" 4 | #include 5 | 6 | uvlong 7 | nsec(void) { 8 | struct timeval tv; 9 | 10 | gettimeofday(&tv, nil); 11 | return (uvlong)tv.tv_sec * 1000000000 + (uvlong)tv.tv_usec * 1000; 12 | } 13 | 14 | -------------------------------------------------------------------------------- /lib/libstuff/util/pathsearch.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2008-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include 5 | #include 6 | #include 7 | #include "util.h" 8 | 9 | char* 10 | pathsearch(const char *path, const char *file, bool slashok) { 11 | char *orig, *p, *s; 12 | 13 | if(!slashok && strchr(file, '/') > file) 14 | file = sxprint("%s/%s", getcwd(buffer, sizeof buffer), file); 15 | else if(!strncmp(file, "./", 2)) 16 | file = sxprint("%s/%s", getcwd(buffer, sizeof buffer), file+2); 17 | if(file[0] == '/') { 18 | if(access(file, X_OK)) 19 | return strdup(file); 20 | return nil; 21 | } 22 | 23 | orig = estrdup(path ? path : getenv("PATH")); 24 | for(p=orig; (s=strtok(p, ":")); p=nil) { 25 | s = smprint("%s/%s", s, file); 26 | if(!access(s, X_OK)) 27 | break; 28 | free(s); 29 | } 30 | free(orig); 31 | return s; 32 | } 33 | -------------------------------------------------------------------------------- /lib/libstuff/util/refree.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2008-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "util.h" 5 | 6 | void 7 | refree(Regex *r) { 8 | 9 | free(r->regex); 10 | free(r->regc); 11 | r->regex = nil; 12 | r->regc = nil; 13 | } 14 | -------------------------------------------------------------------------------- /lib/libstuff/util/reinit.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2008-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "util.h" 5 | 6 | 7 | void 8 | reinit(Regex *r, char *regx) { 9 | 10 | refree(r); 11 | 12 | if(regx[0] != '\0') { 13 | r->regex = estrdup(regx); 14 | r->regc = regcomp(regx); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /lib/libstuff/util/spawn3.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2008-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include 5 | #include 6 | #include "util.h" 7 | 8 | int 9 | spawn3(int fd[3], const char *file, char *argv[]) { 10 | /* Some ideas from Russ Cox's libthread port. */ 11 | int p[2]; 12 | int pid; 13 | 14 | if(pipe(p) < 0) 15 | return -1; 16 | closeexec(p[1]); 17 | 18 | switch(pid = doublefork()) { 19 | case 0: 20 | dup2(fd[0], 0); 21 | dup2(fd[1], 1); 22 | dup2(fd[2], 2); 23 | 24 | execvp(file, argv); 25 | write(p[1], &errno, sizeof errno); 26 | exit(1); 27 | break; 28 | default: 29 | close(p[1]); 30 | if(read(p[0], &errno, sizeof errno) == sizeof errno) 31 | pid = -1; 32 | close(p[0]); 33 | break; 34 | case -1: /* can't happen */ 35 | break; 36 | } 37 | 38 | close(fd[0]); 39 | /* These could fail if any of these was also a previous fd. */ 40 | close(fd[1]); 41 | close(fd[2]); 42 | return pid; 43 | } 44 | -------------------------------------------------------------------------------- /lib/libstuff/util/spawn3l.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2008-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include 5 | #include "util.h" 6 | 7 | int 8 | spawn3l(int fd[3], const char *file, ...) { 9 | va_list ap; 10 | char **argv; 11 | int i, n; 12 | 13 | va_start(ap, file); 14 | for(n=0; va_arg(ap, char*); n++) 15 | ; 16 | va_end(ap); 17 | 18 | argv = emalloc((n+1) * sizeof *argv); 19 | va_start(ap, file); 20 | quotefmtinstall(); 21 | for(i=0; i <= n; i++) 22 | argv[i] = va_arg(ap, char*); 23 | va_end(ap); 24 | 25 | i = spawn3(fd, file, argv); 26 | free(argv); 27 | return i; 28 | } 29 | -------------------------------------------------------------------------------- /lib/libstuff/util/stokenize.c: -------------------------------------------------------------------------------- 1 | /* Written by Kris Maglione */ 2 | /* Public domain */ 3 | #include 4 | #include "util.h" 5 | 6 | uint 7 | stokenize(char *res[], uint reslen, char *str, char *delim) { 8 | char *s; 9 | uint i; 10 | 11 | i = 0; 12 | s = str; 13 | while(i < reslen && *s) { 14 | while(*s && strchr(delim, *s)) 15 | *(s++) = '\0'; 16 | if(*s) 17 | res[i++] = s; 18 | while(*s && !strchr(delim, *s)) 19 | s++; 20 | } 21 | return i; 22 | } 23 | -------------------------------------------------------------------------------- /lib/libstuff/util/strcasestr.c: -------------------------------------------------------------------------------- 1 | /* Written by Kris Maglione */ 2 | /* Public domain */ 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include "util.h" 8 | 9 | /* TODO: Make this UTF-8 compliant. */ 10 | char* 11 | strcasestr(const char *dst, const char *src) { 12 | int len, dc, sc; 13 | 14 | if(src[0] == '\0') 15 | return (char*)(uintptr_t)dst; 16 | 17 | len = strlen(src) - 1; 18 | sc = tolower(src[0]); 19 | for(; (dc = *dst); dst++) { 20 | dc = tolower(dc); 21 | if(sc == dc && (len == 0 || !strncasecmp(dst+1, src+1, len))) 22 | return (char*)(uintptr_t)dst; 23 | } 24 | return nil; 25 | } 26 | -------------------------------------------------------------------------------- /lib/libstuff/util/strend.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2008-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include 5 | #include 6 | 7 | char* 8 | strend(char *s, int n) { 9 | int len; 10 | 11 | len = strlen(s); 12 | return s + max(0, len - n); 13 | } 14 | -------------------------------------------------------------------------------- /lib/libstuff/util/strlcat.c: -------------------------------------------------------------------------------- 1 | /* Written by Kris Maglione */ 2 | /* Public domain */ 3 | #include "util.h" 4 | 5 | uint 6 | strlcat(char *dst, const char *src, uint size) { 7 | const char *s; 8 | char *d; 9 | int n, len; 10 | 11 | d = dst; 12 | s = src; 13 | n = size; 14 | while(n-- > 0 && *d != '\0') 15 | d++; 16 | len = n; 17 | 18 | while(*s != '\0') { 19 | if(n-- > 0) 20 | *d++ = *s; 21 | s++; 22 | } 23 | if(len > 0) 24 | *d = '\0'; 25 | return size - n - 1; 26 | } 27 | -------------------------------------------------------------------------------- /lib/libstuff/util/strlcatprint.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2008-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include 5 | #include 6 | #include "util.h" 7 | 8 | int 9 | strlcatprint(char *buf, int len, const char *fmt, ...) { 10 | va_list ap; 11 | int buflen; 12 | int ret; 13 | 14 | va_start(ap, fmt); 15 | buflen = strlen(buf); 16 | ret = vsnprint(buf+buflen, len-buflen, fmt, ap); 17 | va_end(ap); 18 | return ret; 19 | } 20 | -------------------------------------------------------------------------------- /lib/libstuff/util/sxprint.c: -------------------------------------------------------------------------------- 1 | /* Written by Kris Maglione */ 2 | /* Public domain */ 3 | #include "util.h" 4 | 5 | char* 6 | sxprint(const char *fmt, ...) { 7 | va_list ap; 8 | char *ret; 9 | 10 | va_start(ap, fmt); 11 | ret = vsxprint(fmt, ap); 12 | va_end(ap); 13 | return ret; 14 | } 15 | -------------------------------------------------------------------------------- /lib/libstuff/util/tokenize.c: -------------------------------------------------------------------------------- 1 | /* Written by Kris Maglione */ 2 | /* Public domain */ 3 | #include "util.h" 4 | 5 | uint 6 | tokenize(char *res[], uint reslen, char *str, char delim) { 7 | char *s; 8 | uint i; 9 | 10 | i = 0; 11 | s = str; 12 | while(i < reslen && *s) { 13 | while(*s == delim) 14 | *(s++) = '\0'; 15 | if(*s) 16 | res[i++] = s; 17 | while(*s && *s != delim) 18 | s++; 19 | } 20 | return i; 21 | } 22 | -------------------------------------------------------------------------------- /lib/libstuff/util/trim.c: -------------------------------------------------------------------------------- 1 | /* Written by Kris Maglione */ 2 | /* Public domain */ 3 | #include "util.h" 4 | 5 | void 6 | trim(char *str, const char *chars) { 7 | const char *r; 8 | char *p, *q; 9 | 10 | for(p=str, q=str; *p; p++) { 11 | for(r=chars; *r; r++) 12 | if(*p == *r) 13 | break; 14 | if(!*r) 15 | *q++ = *p; 16 | } 17 | *q = '\0'; 18 | } 19 | 20 | -------------------------------------------------------------------------------- /lib/libstuff/util/uniq.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2008-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include 5 | #include "util.h" 6 | 7 | void 8 | uniq(char **toks) { 9 | char **p, **q; 10 | 11 | q = toks; 12 | if(*q == nil) 13 | return; 14 | for(p=q+1; *p; p++) 15 | if(strcmp(*q, *p)) 16 | *++q = *p; 17 | *++q = nil; 18 | } 19 | -------------------------------------------------------------------------------- /lib/libstuff/util/unmask.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2008-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include 5 | #include "util.h" 6 | 7 | int 8 | unmask(Fmt *f, long mask, char **table, long sep) { 9 | int i, nfmt; 10 | 11 | nfmt = f->nfmt; 12 | for(i=0; table[i]; i++) 13 | if(*table[i] && (mask & (1<nfmt > nfmt) 15 | fmtrune(f, sep); 16 | if(fmtstrcpy(f, table[i])) 17 | return -1; 18 | } 19 | return 0; 20 | } 21 | 22 | -------------------------------------------------------------------------------- /lib/libstuff/util/unquote.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2008-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "util.h" 5 | 6 | int 7 | unquote(char *buf, char *toks[], int ntoks) { 8 | char *s, *t; 9 | bool inquote; 10 | int n; 11 | 12 | n = 0; 13 | s = buf; 14 | while(*s && n < ntoks) { 15 | while(*s && utfrune(" \t\r\n", *s)) 16 | s++; 17 | inquote = false; 18 | toks[n] = s; 19 | t = s; 20 | while(*s && (inquote || !utfrune(" \t\r\n", *s))) { 21 | if(*s == '\'') { 22 | if(inquote && s[1] == '\'') 23 | *t++ = *s++; 24 | else 25 | inquote = !inquote; 26 | } 27 | else 28 | *t++ = *s; 29 | s++; 30 | } 31 | if(*s) 32 | s++; 33 | *t = '\0'; 34 | if(s != toks[n]) 35 | n++; 36 | } 37 | return n; 38 | } 39 | -------------------------------------------------------------------------------- /lib/libstuff/util/utflcpy.c: -------------------------------------------------------------------------------- 1 | /* Written by Kris Maglione */ 2 | /* Public domain */ 3 | #include "util.h" 4 | 5 | int 6 | utflcpy(char *to, const char *from, int l) { 7 | char *p; 8 | 9 | p = utfecpy(to, to+l, from); 10 | return p-to; 11 | } 12 | -------------------------------------------------------------------------------- /lib/libstuff/util/util.h: -------------------------------------------------------------------------------- 1 | /* Written by Kris Maglione */ 2 | /* Public domain */ 3 | #include 4 | 5 | void mfatal(char*, uint); 6 | -------------------------------------------------------------------------------- /lib/libstuff/util/vsxprint.c: -------------------------------------------------------------------------------- 1 | /* Written by Kris Maglione */ 2 | /* Public domain */ 3 | #include 4 | #include "util.h" 5 | 6 | char* 7 | vsxprint(const char *fmt, va_list ap) { 8 | char *s; 9 | 10 | s = vsmprint(fmt, ap); 11 | freelater(s); 12 | return s; 13 | } 14 | -------------------------------------------------------------------------------- /lib/libstuff/x11/colors/loadcolor.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2007-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include 5 | #include "../x11.h" 6 | 7 | int 8 | loadcolor(CTuple *c, const char *str, const char *end) { 9 | char buf[128]; 10 | char *toks[4]; 11 | 12 | memset(c, 0, sizeof(*c)); 13 | 14 | utflcpy(buf, str, end ? min(end - str + 1, sizeof buf) : sizeof buf); 15 | if(3 > stokenize(toks, nelem(toks), buf, " \t\r\n")) 16 | return 0; 17 | 18 | if(!(parsecolor(toks[0], &c->fg) 19 | && parsecolor(toks[1], &c->bg) 20 | && parsecolor(toks[2], &c->border))) 21 | return 0; 22 | 23 | snprint(c->colstr, sizeof c->colstr, "%L %L %L", c->fg, c->bg, c->border); 24 | return toks[2] + strlen(toks[2]) - buf; 25 | } 26 | -------------------------------------------------------------------------------- /lib/libstuff/x11/colors/parsecolor.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2007-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "../x11.h" 5 | 6 | ulong 7 | pixelvalue(Window *w, Color *c) { 8 | XColor xc; 9 | 10 | if(w->visual == nil || w->visual->class != TrueColor) { 11 | if(c->pixel != ~0UL) 12 | return c->pixel; 13 | xc.red = c->red; 14 | xc.green = c->green; 15 | xc.blue = c->blue; 16 | XAllocColor(display, w->colormap, &xc); 17 | return c->pixel = xc.pixel; 18 | } 19 | if(w->depth == 32 || c->alpha == 0) 20 | return (((ulong)c->alpha & 0xff00) << 16) 21 | | (((ulong)c->red & 0xff00) << 8) 22 | | (((ulong)c->green & 0xff00) << 0) 23 | | (((ulong)c->blue & 0xff00) >> 8); 24 | else 25 | return ((ulong)c->red * 0xffff / c->alpha & 0xff00) << 8 26 | | ((ulong)c->green * 0xffff / c->alpha & 0xff00) << 0 27 | | ((ulong)c->blue * 0xffff / c->alpha & 0xff00) >> 8; 28 | } 29 | 30 | bool 31 | parsecolor(const char *name, Color *ret) { 32 | ret->pixel = ~0UL; 33 | return XRenderParseColor(display, (char*)(uintptr_t)name, (XRenderColor*)ret); 34 | } 35 | -------------------------------------------------------------------------------- /lib/libstuff/x11/colors/xftcolor.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2007-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "../x11.h" 5 | 6 | XftColor* 7 | xftcolor(Image *i, Color *c) { 8 | XftColor *xc; 9 | 10 | xc = emallocz(sizeof *c); 11 | *xc = (XftColor){ pixelvalue(i, c), c->red, c->green, c->blue, c->alpha }; 12 | return freelater(xc); 13 | } 14 | -------------------------------------------------------------------------------- /lib/libstuff/x11/convpts.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2007-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "x11.h" 5 | 6 | XPoint* 7 | convpts(Point *pt, int np) { 8 | XPoint *rp; 9 | int i; 10 | 11 | rp = emalloc(np * sizeof *rp); 12 | for(i = 0; i < np; i++) { 13 | rp[i].x = pt[i].x; 14 | rp[i].y = pt[i].y; 15 | } 16 | return rp; 17 | } 18 | -------------------------------------------------------------------------------- /lib/libstuff/x11/drawing/border.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2007-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "../x11.h" 5 | 6 | void 7 | border(Image *dst, Rectangle r, int w, Color *col) { 8 | if(w == 0) 9 | return; 10 | 11 | r = insetrect(r, w/2); 12 | r.max.x -= w%2; 13 | r.max.y -= w%2; 14 | 15 | XSetLineAttributes(display, dst->gc, w, LineSolid, CapButt, JoinMiter); 16 | setgccol(dst, col); 17 | XDrawRectangle(display, dst->xid, dst->gc, 18 | r.min.x, r.min.y, Dx(r), Dy(r)); 19 | } 20 | -------------------------------------------------------------------------------- /lib/libstuff/x11/drawing/drawline.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2007-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "../x11.h" 5 | 6 | void 7 | drawline(Image *dst, Point p1, Point p2, int cap, int w, Color *col) { 8 | XSetLineAttributes(display, dst->gc, w, LineSolid, cap, JoinMiter); 9 | setgccol(dst, col); 10 | XDrawLine(display, dst->xid, dst->gc, p1.x, p1.y, p2.x, p2.y); 11 | } 12 | -------------------------------------------------------------------------------- /lib/libstuff/x11/drawing/drawpoly.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2007-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "../x11.h" 5 | 6 | void 7 | drawpoly(Image *dst, Point *pt, int np, int cap, int w, Color *col) { 8 | XPoint *xp; 9 | 10 | xp = convpts(pt, np); 11 | XSetLineAttributes(display, dst->gc, w, LineSolid, cap, JoinMiter); 12 | setgccol(dst, col); 13 | XDrawLines(display, dst->xid, dst->gc, xp, np, CoordModeOrigin); 14 | free(xp); 15 | } 16 | -------------------------------------------------------------------------------- /lib/libstuff/x11/drawing/fill.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2007-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "../x11.h" 5 | 6 | void 7 | fill(Image *dst, Rectangle r, Color *col) { 8 | setgccol(dst, col); 9 | XFillRectangle(display, dst->xid, dst->gc, 10 | r.min.x, r.min.y, Dx(r), Dy(r)); 11 | } 12 | -------------------------------------------------------------------------------- /lib/libstuff/x11/drawing/fillpoly.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2007-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "../x11.h" 5 | 6 | void 7 | fillpoly(Image *dst, Point *pt, int np, Color *col) { 8 | XPoint *xp; 9 | 10 | xp = convpts(pt, np); 11 | setgccol(dst, col); 12 | XFillPolygon(display, dst->xid, dst->gc, xp, np, Complex, CoordModeOrigin); 13 | free(xp); 14 | } 15 | -------------------------------------------------------------------------------- /lib/libstuff/x11/drawing/setgccol.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2007-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "../x11.h" 5 | 6 | void 7 | setgccol(Image *dst, Color *c) { 8 | XSetForeground(display, dst->gc, pixelvalue(dst, c)); 9 | } 10 | -------------------------------------------------------------------------------- /lib/libstuff/x11/errors.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2007-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "x11.h" 5 | 6 | extern ErrorCode ignored_xerrors[]; 7 | static bool _trap_errors; 8 | static long nerrors; 9 | 10 | int 11 | errorhandler(Display *dpy, XErrorEvent *error) { 12 | ErrorCode *e; 13 | 14 | USED(dpy); 15 | 16 | if(_trap_errors) { 17 | nerrors++; 18 | return 0; 19 | } 20 | 21 | e = ignored_xerrors; 22 | if(e) 23 | for(; e->rcode || e->ecode; e++) 24 | if((e->rcode == 0 || e->rcode == error->request_code) 25 | && (e->ecode == 0 || e->ecode == error->error_code)) 26 | return 0; 27 | 28 | fprint(2, "%s: fatal error: Xrequest code=%d, Xerror code=%d\n", 29 | argv0, error->request_code, error->error_code); 30 | return xlib_errorhandler(display, error); /* calls exit() */ 31 | } 32 | 33 | int 34 | traperrors(bool enable) { 35 | 36 | sync(); 37 | _trap_errors = enable; 38 | if (enable) 39 | nerrors = 0; 40 | return nerrors; 41 | } 42 | -------------------------------------------------------------------------------- /lib/libstuff/x11/focus/getfocus.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2007-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "../x11.h" 5 | 6 | XWindow 7 | getfocus(void) { 8 | XWindow ret; 9 | int revert; 10 | 11 | XGetInputFocus(display, &ret, &revert); 12 | return ret; 13 | } 14 | -------------------------------------------------------------------------------- /lib/libstuff/x11/focus/setfocus.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2007-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "../x11.h" 5 | 6 | void 7 | setfocus(Window *w, int mode) { 8 | XSetInputFocus(display, w->xid, mode, CurrentTime); 9 | } 10 | -------------------------------------------------------------------------------- /lib/libstuff/x11/freestringlist.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2007-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "x11.h" 5 | 6 | void 7 | freestringlist(char *list[]) { 8 | XFreeStringList(list); 9 | } 10 | -------------------------------------------------------------------------------- /lib/libstuff/x11/geometry/XRect.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2007-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "../x11.h" 5 | 6 | XRectangle 7 | XRect(Rectangle r) { 8 | XRectangle xr; 9 | 10 | xr.x = r.min.x; 11 | xr.y = r.min.y; 12 | xr.width = Dx(r); 13 | xr.height = Dy(r); 14 | return xr; 15 | } 16 | -------------------------------------------------------------------------------- /lib/libstuff/x11/geometry/addpt.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2007-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "../x11.h" 5 | 6 | Point 7 | addpt(Point p, Point q) { 8 | p.x += q.x; 9 | p.y += q.y; 10 | return p; 11 | } 12 | -------------------------------------------------------------------------------- /lib/libstuff/x11/geometry/divpt.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2007-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "../x11.h" 5 | 6 | Point 7 | divpt(Point p, Point q) { 8 | p.x /= q.x; 9 | p.y /= q.y; 10 | return p; 11 | } 12 | -------------------------------------------------------------------------------- /lib/libstuff/x11/geometry/eqpt.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2007-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "../x11.h" 5 | 6 | int 7 | eqpt(Point p, Point q) { 8 | return p.x==q.x && p.y==q.y; 9 | } 10 | -------------------------------------------------------------------------------- /lib/libstuff/x11/geometry/eqrect.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2007-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "../x11.h" 5 | 6 | int 7 | eqrect(Rectangle a, Rectangle b) { 8 | return a.min.x==b.min.x && a.max.x==b.max.x 9 | && a.min.y==b.min.y && a.max.y==b.max.y; 10 | } 11 | -------------------------------------------------------------------------------- /lib/libstuff/x11/geometry/insetrect.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2007-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "../x11.h" 5 | 6 | Rectangle 7 | insetrect(Rectangle r, int n) { 8 | r.min.x += n; 9 | r.min.y += n; 10 | r.max.x -= n; 11 | r.max.y -= n; 12 | return r; 13 | } 14 | -------------------------------------------------------------------------------- /lib/libstuff/x11/geometry/mulpt.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2007-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "../x11.h" 5 | 6 | Point 7 | mulpt(Point p, Point q) { 8 | p.x *= q.x; 9 | p.y *= q.y; 10 | return p; 11 | } 12 | -------------------------------------------------------------------------------- /lib/libstuff/x11/geometry/rectaddpt.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2007-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "../x11.h" 5 | 6 | Rectangle 7 | rectaddpt(Rectangle r, Point p) { 8 | r.min.x += p.x; 9 | r.max.x += p.x; 10 | r.min.y += p.y; 11 | r.max.y += p.y; 12 | return r; 13 | } 14 | -------------------------------------------------------------------------------- /lib/libstuff/x11/geometry/rectsetorigin.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2007-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "../x11.h" 5 | 6 | Rectangle 7 | rectsetorigin(Rectangle r, Point p) { 8 | Rectangle ret; 9 | 10 | ret.min.x = p.x; 11 | ret.min.y = p.y; 12 | ret.max.x = p.x + Dx(r); 13 | ret.max.y = p.y + Dy(r); 14 | return ret; 15 | } 16 | -------------------------------------------------------------------------------- /lib/libstuff/x11/geometry/rectsubpt.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2007-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "../x11.h" 5 | 6 | Rectangle 7 | rectsubpt(Rectangle r, Point p) { 8 | r.min.x -= p.x; 9 | r.max.x -= p.x; 10 | r.min.y -= p.y; 11 | r.max.y -= p.y; 12 | return r; 13 | } 14 | -------------------------------------------------------------------------------- /lib/libstuff/x11/geometry/subpt.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2007-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "../x11.h" 5 | 6 | Point 7 | subpt(Point p, Point q) { 8 | p.x -= q.x; 9 | p.y -= q.y; 10 | return p; 11 | } 12 | -------------------------------------------------------------------------------- /lib/libstuff/x11/ignored_xerrors.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2007-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "x11.h" 5 | 6 | ErrorCode ignored_xerrors[] = { 7 | { 0, }, 8 | }; 9 | 10 | -------------------------------------------------------------------------------- /lib/libstuff/x11/images/allocimage.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2007-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "../x11.h" 5 | 6 | Image* 7 | allocimage(int w, int h, int depth) { 8 | Image *img; 9 | 10 | img = emallocz(sizeof *img); 11 | img->type = WImage; 12 | img->xid = XCreatePixmap(display, scr.root.xid, w, h, depth); 13 | img->gc = XCreateGC(display, img->xid, 0, nil); 14 | img->colormap = scr.colormap; 15 | img->visual = scr.visual; 16 | if(depth == 32) 17 | img->visual = scr.visual32; 18 | img->depth = depth; 19 | img->r = Rect(0, 0, w, h); 20 | return img; 21 | } 22 | -------------------------------------------------------------------------------- /lib/libstuff/x11/images/copyimage.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2007-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "../x11.h" 5 | 6 | void 7 | copyimage(Image *dst, Rectangle r, Image *src, Point p) { 8 | XCopyArea(display, 9 | src->xid, dst->xid, 10 | dst->gc, 11 | r.min.x, r.min.y, Dx(r), Dy(r), 12 | p.x, p.y); 13 | } 14 | -------------------------------------------------------------------------------- /lib/libstuff/x11/images/freeimage.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2007-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "../x11.h" 5 | 6 | void 7 | freeimage(Image *img) { 8 | if(img == nil) 9 | return; 10 | 11 | assert(img->type == WImage); 12 | 13 | if(img->xft) 14 | xft->drawdestroy(img->xft); 15 | XFreePixmap(display, img->xid); 16 | XFreeGC(display, img->gc); 17 | free(img); 18 | } 19 | -------------------------------------------------------------------------------- /lib/libstuff/x11/images/xftdrawable.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2007-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "../x11.h" 5 | 6 | XftDraw* 7 | xftdrawable(Image *img) { 8 | if(img->xft == nil) 9 | img->xft = xft->drawcreate(display, img->xid, img->visual, img->colormap); 10 | return img->xft; 11 | } 12 | -------------------------------------------------------------------------------- /lib/libstuff/x11/insanity/gravitate.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2007-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "../x11.h" 5 | 6 | Rectangle 7 | gravitate(Rectangle rc, Rectangle rf, Point grav) { 8 | Point d; 9 | 10 | /* Get delta between frame and client rectangles */ 11 | d = subpt(subpt(rf.max, rf.min), 12 | subpt(rc.max, rc.min)); 13 | 14 | /* Divide by 2 and apply gravity */ 15 | d = divpt(d, Pt(2, 2)); 16 | d = mulpt(d, grav); 17 | 18 | return rectsubpt(rc, d); 19 | } 20 | -------------------------------------------------------------------------------- /lib/libstuff/x11/insanity/sizehint.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2007-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "../x11.h" 5 | 6 | Rectangle 7 | sizehint(WinHints *h, Rectangle r) { 8 | Point p, aspect, origin; 9 | 10 | if(h == nil) 11 | return r; 12 | 13 | origin = r.min; 14 | r = rectsubpt(r, origin); 15 | 16 | /* Min/max */ 17 | r.max.x = max(r.max.x, h->min.x); 18 | r.max.y = max(r.max.y, h->min.y); 19 | r.max.x = min(r.max.x, h->max.x); 20 | r.max.y = min(r.max.y, h->max.y); 21 | 22 | /* Increment */ 23 | p = subpt(r.max, h->base); 24 | r.max.x -= p.x % h->inc.x; 25 | r.max.y -= p.y % h->inc.y; 26 | 27 | /* Aspect */ 28 | p = subpt(r.max, h->baspect); 29 | p.y = max(p.y, 1); 30 | 31 | aspect = h->aspect.min; 32 | if(p.x * aspect.y / p.y < aspect.x) 33 | r.max.y = h->baspect.y 34 | + p.x * aspect.y / aspect.x; 35 | 36 | aspect = h->aspect.max; 37 | if(p.x * aspect.y / p.y > aspect.x) 38 | r.max.x = h->baspect.x 39 | + p.y * aspect.x / aspect.y; 40 | 41 | return rectaddpt(r, origin); 42 | } 43 | -------------------------------------------------------------------------------- /lib/libstuff/x11/keyboard/grabkeyboard.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2007-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "../x11.h" 5 | 6 | int 7 | grabkeyboard(Window *w) { 8 | 9 | return XGrabKeyboard(display, w->xid, true /* owner events */, 10 | GrabModeAsync, GrabModeAsync, CurrentTime 11 | ) == GrabSuccess; 12 | } 13 | -------------------------------------------------------------------------------- /lib/libstuff/x11/keyboard/ungrabkeyboard.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2007-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "../x11.h" 5 | 6 | void 7 | ungrabkeyboard(void) { 8 | XUngrabKeyboard(display, CurrentTime); 9 | } 10 | -------------------------------------------------------------------------------- /lib/libstuff/x11/keys/keycode.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2007-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "../x11.h" 5 | 6 | KeyCode 7 | keycode(const char *name) { 8 | return XKeysymToKeycode(display, XStringToKeysym(name)); 9 | } 10 | -------------------------------------------------------------------------------- /lib/libstuff/x11/mouse/grabpointer.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2007-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "../x11.h" 5 | 6 | int 7 | grabpointer(Window *w, Window *confine, Cursor cur, int mask) { 8 | XWindow cw; 9 | 10 | cw = None; 11 | if(confine) 12 | cw = confine->xid; 13 | return XGrabPointer(display, w->xid, false /* owner events */, mask, 14 | GrabModeAsync, GrabModeAsync, cw, cur, CurrentTime 15 | ) == GrabSuccess; 16 | } 17 | -------------------------------------------------------------------------------- /lib/libstuff/x11/mouse/pointerscreen.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2007-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "../x11.h" 5 | 6 | int 7 | pointerscreen(void) { 8 | XWindow win; 9 | Point pt; 10 | uint ui; 11 | int i; 12 | 13 | return XQueryPointer(display, scr.root.xid, &win, &win, &i, &i, 14 | &pt.x, &pt.y, &ui); 15 | } 16 | -------------------------------------------------------------------------------- /lib/libstuff/x11/mouse/querypointer.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2007-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "../x11.h" 5 | 6 | Point 7 | querypointer(Window *w) { 8 | XWindow win; 9 | Point pt; 10 | uint ui; 11 | int i; 12 | 13 | XQueryPointer(display, w->xid, &win, &win, &i, &i, &pt.x, &pt.y, &ui); 14 | return pt; 15 | } 16 | -------------------------------------------------------------------------------- /lib/libstuff/x11/mouse/translate.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2007-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "../x11.h" 5 | 6 | Point 7 | translate(Window *src, Window *dst, Point sp) { 8 | Point pt; 9 | XWindow w; 10 | 11 | XTranslateCoordinates(display, src->xid, dst->xid, sp.x, sp.y, 12 | &pt.x, &pt.y, &w); 13 | return pt; 14 | } 15 | -------------------------------------------------------------------------------- /lib/libstuff/x11/mouse/ungrabpointer.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2007-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "../x11.h" 5 | 6 | void 7 | ungrabpointer(void) { 8 | XUngrabPointer(display, CurrentTime); 9 | } 10 | -------------------------------------------------------------------------------- /lib/libstuff/x11/mouse/warppointer.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2007-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "../x11.h" 5 | 6 | void 7 | warppointer(Point pt) { 8 | /* Nasty kludge for xephyr, xnest. */ 9 | static int havereal = -1; 10 | static char* real; 11 | 12 | if(havereal == -1) { 13 | real = getenv("REALDISPLAY"); 14 | havereal = real != nil; 15 | } 16 | if(havereal) 17 | system(sxprint("DISPLAY=%s wiwarp %d %d", real, pt.x, pt.y)); 18 | 19 | XWarpPointer(display, 20 | /* src, dest w */ None, scr.root.xid, 21 | /* src_rect */ 0, 0, 0, 0, 22 | /* target */ pt.x, pt.y); 23 | } 24 | -------------------------------------------------------------------------------- /lib/libstuff/x11/properties/changeprop_char.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2007-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "../x11.h" 5 | 6 | void 7 | changeprop_char(Window *w, const char *prop, const char *type, const char data[], int len) { 8 | changeproperty(w, prop, type, 8, (const uchar*)data, len); 9 | } 10 | -------------------------------------------------------------------------------- /lib/libstuff/x11/properties/changeprop_long.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2007-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "../x11.h" 5 | 6 | void 7 | changeprop_long(Window *w, const char *prop, const char *type, long data[], int len) { 8 | changeproperty(w, prop, type, 32, (uchar*)data, len); 9 | } 10 | -------------------------------------------------------------------------------- /lib/libstuff/x11/properties/changeprop_short.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2007-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "../x11.h" 5 | 6 | void 7 | changeprop_short(Window *w, const char *prop, const char *type, short data[], int len) { 8 | changeproperty(w, prop, type, 16, (uchar*)data, len); 9 | } 10 | -------------------------------------------------------------------------------- /lib/libstuff/x11/properties/changeprop_string.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2007-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include 5 | #include "../x11.h" 6 | 7 | void 8 | changeprop_string(Window *w, const char *prop, const char *string) { 9 | changeprop_char(w, prop, "UTF8_STRING", string, strlen(string)); 10 | } 11 | -------------------------------------------------------------------------------- /lib/libstuff/x11/properties/changeprop_textlist.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2007-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include 5 | #include "../x11.h" 6 | 7 | void 8 | changeprop_textlist(Window *w, const char *prop, const char *type, char *data[]) { 9 | char **p, *s, *t; 10 | int len, n; 11 | 12 | len = 0; 13 | for(p=data; *p; p++) 14 | len += strlen(*p) + 1; 15 | s = emalloc(len); 16 | t = s; 17 | for(p=data; *p; p++) { 18 | n = strlen(*p) + 1; 19 | memcpy(t, *p, n); 20 | t += n; 21 | } 22 | changeprop_char(w, prop, type, s, len - 1); 23 | free(s); 24 | } 25 | -------------------------------------------------------------------------------- /lib/libstuff/x11/properties/changeprop_ulong.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2007-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "../x11.h" 5 | 6 | void 7 | changeprop_ulong(Window *w, const char *prop, const char *type, ulong data[], int len) { 8 | changeproperty(w, prop, type, 32, (uchar*)data, len); 9 | } 10 | -------------------------------------------------------------------------------- /lib/libstuff/x11/properties/changeproperty.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2007-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "../x11.h" 5 | 6 | void 7 | changeproperty(Window *w, const char *prop, const char *type, 8 | int width, const uchar data[], int n) { 9 | XChangeProperty(display, w->xid, xatom(prop), xatom(type), width, 10 | PropModeReplace, data, n); 11 | } 12 | -------------------------------------------------------------------------------- /lib/libstuff/x11/properties/delproperty.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2007-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "../x11.h" 5 | 6 | void 7 | delproperty(Window *w, const char *prop) { 8 | XDeleteProperty(display, w->xid, xatom(prop)); 9 | } 10 | -------------------------------------------------------------------------------- /lib/libstuff/x11/properties/getprop.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2007-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "../x11.h" 5 | 6 | ulong 7 | getprop(Window *w, const char *prop, const char *type, Atom *actual, int *format, 8 | ulong offset, uchar **ret, ulong length) { 9 | Atom typea; 10 | ulong n, extra; 11 | int status; 12 | 13 | typea = (type ? xatom(type) : 0L); 14 | 15 | status = XGetWindowProperty(display, w->xid, 16 | xatom(prop), offset, length, false /* delete */, 17 | typea, actual, format, &n, &extra, ret); 18 | 19 | if(status != Success) { 20 | *ret = nil; 21 | return 0; 22 | } 23 | if(n == 0) { 24 | free(*ret); 25 | *ret = nil; 26 | } 27 | return n; 28 | } 29 | -------------------------------------------------------------------------------- /lib/libstuff/x11/properties/getprop_long.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2007-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "../x11.h" 5 | 6 | ulong 7 | getprop_long(Window *w, const char *prop, const char *type, 8 | ulong offset, long **ret, ulong length) { 9 | Atom actual; 10 | ulong n; 11 | int format; 12 | 13 | n = getprop(w, prop, type, &actual, &format, offset, (uchar**)ret, length); 14 | if(n == 0 || format == 32 && xatom(type) == actual) 15 | return n; 16 | free(*ret); 17 | *ret = 0; 18 | return 0; 19 | } 20 | 21 | ulong 22 | getprop_ulong(Window *w, const char *prop, const char *type, 23 | ulong offset, ulong **ret, ulong length) { 24 | return getprop_long(w, prop, type, offset, (long**)ret, length); 25 | } 26 | 27 | -------------------------------------------------------------------------------- /lib/libstuff/x11/properties/getprop_string.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2007-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "../x11.h" 5 | 6 | char* 7 | getprop_string(Window *w, const char *name) { 8 | char **list, *str; 9 | int n; 10 | 11 | str = nil; 12 | 13 | n = getprop_textlist(w, name, &list); 14 | if(n > 0) 15 | str = estrdup(*list); 16 | freestringlist(list); 17 | 18 | return str; 19 | } 20 | -------------------------------------------------------------------------------- /lib/libstuff/x11/properties/getprop_textlist.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2007-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "../x11.h" 5 | 6 | int 7 | getprop_textlist(Window *w, const char *name, char **ret[]) { 8 | XTextProperty prop; 9 | char **list; 10 | int n; 11 | 12 | *ret = nil; 13 | n = 0; 14 | 15 | XGetTextProperty(display, w->xid, &prop, xatom(name)); 16 | if(prop.nitems > 0) { 17 | if(Xutf8TextPropertyToTextList(display, &prop, &list, &n) == Success) 18 | *ret = list; 19 | XFree(prop.value); 20 | } 21 | return n; 22 | } 23 | -------------------------------------------------------------------------------- /lib/libstuff/x11/properties/getproperty.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2007-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "../x11.h" 5 | 6 | ulong 7 | getproperty(Window *w, char *prop, char *type, Atom *actual, 8 | ulong offset, uchar **ret, ulong length) { 9 | int format; 10 | 11 | return getprop(w, prop, type, actual, &format, offset, ret, length); 12 | } 13 | -------------------------------------------------------------------------------- /lib/libstuff/x11/properties/strlistdup.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2007-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include 5 | #include "../x11.h" 6 | 7 | char** 8 | strlistdup(char *list[]) { 9 | char **p; 10 | char *q; 11 | int i, m, n; 12 | 13 | n = 0; 14 | m = 0; 15 | for(p=list; *p; p++, n++) 16 | m += strlen(*p) + 1; 17 | 18 | p = malloc((n+1) * sizeof(*p) + m); 19 | q = (char*)&p[n+1]; 20 | 21 | for(i=0; i < n; i++) { 22 | p[i] = q; 23 | m = strlen(list[i]) + 1; 24 | memcpy(q, list[i], m); 25 | q += m; 26 | } 27 | p[n] = nil; 28 | return p; 29 | } 30 | -------------------------------------------------------------------------------- /lib/libstuff/x11/properties/windowname.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2007-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "../x11.h" 5 | 6 | char* 7 | windowname(Window *w) { 8 | char *str; 9 | 10 | str = getprop_string(w, "_NET_WM_NAME"); 11 | if(str == nil) 12 | str = getprop_string(w, "WM_NAME"); 13 | if(str == nil) 14 | str = estrdup(""); 15 | return str; 16 | } 17 | 18 | -------------------------------------------------------------------------------- /lib/libstuff/x11/sendevent.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2007-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "x11.h" 5 | 6 | void 7 | sendevent(Window *w, bool propagate, long mask, void *e) { 8 | XSendEvent(display, w->xid, propagate, mask, e); 9 | } 10 | 11 | -------------------------------------------------------------------------------- /lib/libstuff/x11/sendmessage.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2007-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "x11.h" 5 | #include 6 | 7 | void 8 | sendmessage(Window *w, const char *name, long l0, long l1, long l2, long l3, long l4) { 9 | 10 | clientmessage(w, name, NoEventMask, 32, (ClientMessageData){ .l = { l0, l1, l2, l3, l4 } }); 11 | } 12 | 13 | void 14 | clientmessage(Window *w, const char *name, long mask, int format, ClientMessageData data) { 15 | XClientMessageEvent e; 16 | 17 | e.type = ClientMessage; 18 | e.window = w->xid; 19 | e.message_type = xatom(name); 20 | e.format = format; 21 | bcopy(&data, &e.data, sizeof(data)); 22 | sendevent(w, false, mask, (XEvent*)&e); 23 | } 24 | 25 | -------------------------------------------------------------------------------- /lib/libstuff/x11/shape/setshapemask.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2007-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "../x11.h" 5 | 6 | void 7 | setshapemask(Window *dst, Image *src, Point pt) { 8 | /* Assumes that we have the shape extension... */ 9 | XShapeCombineMask (display, dst->xid, 10 | ShapeBounding, pt.x, pt.y, src->xid, ShapeSet); 11 | } 12 | -------------------------------------------------------------------------------- /lib/libstuff/x11/sync.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2007-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "x11.h" 5 | 6 | void 7 | sync(void) { 8 | XSync(display, false); 9 | } 10 | -------------------------------------------------------------------------------- /lib/libstuff/x11/text/freefont.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2007-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "../x11.h" 5 | 6 | void 7 | freefont(Font *f) { 8 | switch(f->type) { 9 | case FFontSet: 10 | XFreeFontSet(display, f->font.set); 11 | break; 12 | case FXft: 13 | xft->fontclose(display, f->font.xft); 14 | break; 15 | case FX11: 16 | XFreeFont(display, f->font.x11); 17 | break; 18 | default: 19 | break; 20 | } 21 | free(f->name); 22 | free(f); 23 | } 24 | -------------------------------------------------------------------------------- /lib/libstuff/x11/text/labelh.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2007-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "../x11.h" 5 | 6 | uint 7 | labelh(Font *font) { 8 | return max(font->height + font->descent + font->pad.min.y + font->pad.max.y, 1); 9 | } 10 | -------------------------------------------------------------------------------- /lib/libstuff/x11/text/textextents_l.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2007-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "../x11.h" 5 | 6 | Rectangle 7 | textextents_l(Font *font, const char *text, uint len, int *offset) { 8 | Rectangle rect; 9 | XRectangle r; 10 | XGlyphInfo i; 11 | int unused; 12 | 13 | if(!offset) 14 | offset = &unused; 15 | 16 | switch(font->type) { 17 | case FFontSet: 18 | *offset = Xutf8TextExtents(font->font.set, text, len, &r, nil); 19 | return Rect(r.x, -r.y - r.height, r.x + r.width, -r.y); 20 | case FXft: 21 | xft->textextents(display, font->font.xft, text, len, &i); 22 | *offset = i.xOff; 23 | return Rect(-i.x, i.y - i.height, -i.x + i.width, i.y); 24 | case FX11: 25 | rect = ZR; 26 | rect.max.x = XTextWidth(font->font.x11, text, len); 27 | rect.max.y = font->ascent; 28 | *offset = rect.max.x; 29 | return rect; 30 | default: 31 | die("Invalid font type"); 32 | return ZR; /* shut up ken */ 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /lib/libstuff/x11/text/textwidth.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2007-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include 5 | #include "../x11.h" 6 | 7 | uint 8 | textwidth(Font *font, const char *text) { 9 | return textwidth_l(font, text, strlen(text)); 10 | } 11 | -------------------------------------------------------------------------------- /lib/libstuff/x11/text/textwidth_l.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2007-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "../x11.h" 5 | 6 | uint 7 | textwidth_l(Font *font, const char *text, uint len) { 8 | Rectangle r; 9 | 10 | r = textextents_l(font, text, len, nil); 11 | return Dx(r); 12 | } 13 | -------------------------------------------------------------------------------- /lib/libstuff/x11/windows/configwin.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2007-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "../x11.h" 5 | 6 | void 7 | configwin(Window *w, Rectangle r, int border) { 8 | XWindowChanges wc; 9 | 10 | if(eqrect(r, w->r) && border == w->border) 11 | return; 12 | 13 | wc.x = r.min.x - border; 14 | wc.y = r.min.y - border; 15 | wc.width = Dx(r); 16 | wc.height = Dy(r); 17 | wc.border_width = border; 18 | XConfigureWindow(display, w->xid, CWX|CWY|CWWidth|CWHeight|CWBorderWidth, &wc); 19 | 20 | w->r = r; 21 | w->border = border; 22 | } 23 | -------------------------------------------------------------------------------- /lib/libstuff/x11/windows/createwindow.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2007-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "../x11.h" 5 | 6 | Window* 7 | createwindow(Window *parent, Rectangle r, int depth, uint class, WinAttr *wa, int valmask) { 8 | return createwindow_visual(parent, r, depth, scr.visual, class, wa, valmask); 9 | } 10 | -------------------------------------------------------------------------------- /lib/libstuff/x11/windows/createwindow_rgba.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2007-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "../x11.h" 5 | 6 | Window* 7 | createwindow_rgba(Window *parent, Rectangle r, WinAttr *wa, int valmask) { 8 | WinAttr attr; 9 | 10 | if(scr.visual32 == nil) 11 | return createwindow(parent, r, scr.depth, InputOutput, wa, valmask); 12 | 13 | attr = wa ? *wa : (WinAttr){0}; 14 | valmask |= CWBorderPixel | CWColormap; 15 | attr.border_pixel = 0; 16 | attr.colormap = scr.colormap32; 17 | return createwindow_visual(parent, r, 32, scr.visual32, InputOutput, &attr, valmask); 18 | } 19 | -------------------------------------------------------------------------------- /lib/libstuff/x11/windows/destroywindow.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2007-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "../x11.h" 5 | 6 | void 7 | cleanupwindow(Window *w) { 8 | assert(w->type == WWindow); 9 | sethandler(w, nil); 10 | while(w->handler_link) 11 | pophandler(w, w->handler_link->handler); 12 | free(w->hints); 13 | free(w->dnd); 14 | if(w->xft) 15 | xft->drawdestroy(w->xft); 16 | if(w->gc) 17 | XFreeGC(display, w->gc); 18 | } 19 | 20 | void 21 | destroywindow(Window *w) { 22 | cleanupwindow(w); 23 | XDestroyWindow(display, w->xid); 24 | free(w); 25 | } 26 | -------------------------------------------------------------------------------- /lib/libstuff/x11/windows/findwin.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2007-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "../x11.h" 5 | #include 6 | 7 | Window* 8 | findwin(XWindow xw) { 9 | Window *w; 10 | void **e; 11 | 12 | e = map_get(&windowmap, (ulong)xw, false); 13 | if(e) { 14 | w = *e; 15 | assert(w->xid == xw); 16 | return w; 17 | } 18 | return nil; 19 | } 20 | -------------------------------------------------------------------------------- /lib/libstuff/x11/windows/getwinrect.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2007-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "../x11.h" 5 | 6 | Rectangle 7 | getwinrect(Window *w) { 8 | XWindowAttributes wa; 9 | Point p; 10 | 11 | if(!XGetWindowAttributes(display, w->xid, &wa)) 12 | return ZR; 13 | p = translate(w, &scr.root, ZP); 14 | return rectaddpt(Rect(0, 0, wa.width, wa.height), p); 15 | } 16 | -------------------------------------------------------------------------------- /lib/libstuff/x11/windows/lowerwin.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2007-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "../x11.h" 5 | 6 | void 7 | lowerwin(Window *w) { 8 | assert(w->type == WWindow); 9 | XLowerWindow(display, w->xid); 10 | } 11 | -------------------------------------------------------------------------------- /lib/libstuff/x11/windows/mapwin.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2007-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "../x11.h" 5 | 6 | int 7 | mapwin(Window *w) { 8 | assert(w->type == WWindow); 9 | if(!w->mapped) { 10 | XMapWindow(display, w->xid); 11 | w->mapped = 1; 12 | return 1; 13 | } 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /lib/libstuff/x11/windows/movewin.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2007-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "../x11.h" 5 | 6 | void 7 | movewin(Window *w, Point pt) { 8 | Rectangle r; 9 | 10 | assert(w->type == WWindow); 11 | r = rectsetorigin(w->r, pt); 12 | reshapewin(w, r); 13 | } 14 | -------------------------------------------------------------------------------- /lib/libstuff/x11/windows/raisewin.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2007-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "../x11.h" 5 | 6 | void 7 | raisewin(Window *w) { 8 | assert(w->type == WWindow); 9 | XRaiseWindow(display, w->xid); 10 | } 11 | -------------------------------------------------------------------------------- /lib/libstuff/x11/windows/reparentwindow.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2007-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "../x11.h" 5 | 6 | void 7 | reparentwindow(Window *w, Window *par, Point p) { 8 | assert(w->type == WWindow); 9 | XReparentWindow(display, w->xid, par->xid, p.x, p.y); 10 | w->r = rectsubpt(w->r, w->r.min); 11 | w->r = rectaddpt(w->r, p); 12 | } 13 | -------------------------------------------------------------------------------- /lib/libstuff/x11/windows/reshapewin.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2007-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "../x11.h" 5 | 6 | void 7 | reshapewin(Window *w, Rectangle r) { 8 | assert(w->type == WWindow); 9 | assert(Dx(r) > 0 && Dy(r) > 0); /* Rather than an X error. */ 10 | 11 | configwin(w, r, w->border); 12 | } 13 | -------------------------------------------------------------------------------- /lib/libstuff/x11/windows/selectinput.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2007-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "../x11.h" 5 | 6 | void 7 | selectinput(Window *w, long mask) { 8 | w->eventmask = mask; 9 | XSelectInput(display, w->xid, mask); 10 | } 11 | -------------------------------------------------------------------------------- /lib/libstuff/x11/windows/setborder.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2007-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "../x11.h" 5 | 6 | void 7 | setborder(Window *w, int width, Color *col) { 8 | 9 | assert(w->type == WWindow); 10 | if(width) 11 | XSetWindowBorder(display, w->xid, pixelvalue(w, col)); 12 | if(width != w->border) 13 | configwin(w, w->r, width); 14 | } 15 | -------------------------------------------------------------------------------- /lib/libstuff/x11/windows/setwinattr.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2007-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "../x11.h" 5 | 6 | void 7 | setwinattr(Window *w, WinAttr *wa, int valmask) { 8 | assert(w->type == WWindow); 9 | XChangeWindowAttributes(display, w->xid, valmask, wa); 10 | } 11 | -------------------------------------------------------------------------------- /lib/libstuff/x11/windows/unmapwin.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2007-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "../x11.h" 5 | 6 | int 7 | unmapwin(Window *w) { 8 | assert(w->type == WWindow); 9 | if(w->mapped) { 10 | XUnmapWindow(display, w->xid); 11 | w->mapped = 0; 12 | w->unmapped++; 13 | return 1; 14 | } 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /lib/libstuff/x11/windows/window.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2007-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "../x11.h" 5 | 6 | Window* 7 | window(XWindow xw) { 8 | Window *w; 9 | 10 | w = emallocz(sizeof *w); 11 | w->type = WWindow; 12 | w->xid = xw; 13 | return freelater(w); 14 | } 15 | -------------------------------------------------------------------------------- /lib/libstuff/x11/x11.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2007-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "x11.h" 5 | 6 | const Point ZP = {0, 0}; 7 | const Rectangle ZR = {{0, 0}, {0, 0}}; 8 | 9 | const Window _pointerwin = { .xid = PointerRoot }; 10 | Window* const pointerwin = (Window*)&_pointerwin; 11 | 12 | 13 | -------------------------------------------------------------------------------- /lib/libstuff/x11/x11.h: -------------------------------------------------------------------------------- 1 | /* Copyright ©2007-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | 5 | #define _X11_VISIBLE 6 | #define pointerwin __pointerwin 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #undef pointerwin 16 | 17 | extern int (*xlib_errorhandler) (Display*, XErrorEvent*); 18 | 19 | void configwin(Window*, Rectangle, int); 20 | XPoint* convpts(Point*, int); 21 | int errorhandler(Display*, XErrorEvent*); 22 | void setgccol(Image*, Color*); 23 | XftColor* xftcolor(Image*, Color*); 24 | XftDraw* xftdrawable(Image*); 25 | 26 | -------------------------------------------------------------------------------- /lib/libstuff/x11/xatom.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2007-2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include "x11.h" 5 | 6 | Atom 7 | xatom(const char *name) { 8 | void **e, **f; 9 | 10 | e = hash_get(&atommap, name, true); 11 | if(*e == nil) { 12 | *e = (void*)XInternAtom(display, name, false); 13 | f = map_get(&atomnamemap, (ulong)*e, true); 14 | if(*f == nil) 15 | *f = (void*)(uintptr_t)name; 16 | } 17 | return (Atom)*e; 18 | } 19 | 20 | char* 21 | atomname(ulong atom) { 22 | void **e; 23 | 24 | e = map_get(&atomnamemap, atom, true); 25 | if(*e == nil) { 26 | *e = XGetAtomName(display, atom); 27 | if(*e == nil) { 28 | map_rm(&atomnamemap, atom); 29 | return nil; 30 | } 31 | *hash_get(&atommap, *e, true) = (void*)atom; 32 | } 33 | return *e; 34 | } 35 | 36 | -------------------------------------------------------------------------------- /lib/libstuff/x11/xft.c: -------------------------------------------------------------------------------- 1 | /* Copyright ©2010 Kris Maglione 2 | * See LICENSE file for license details. 3 | */ 4 | #include 5 | #include 6 | 7 | Xft *xft; 8 | 9 | #ifdef HAVE_RTLD 10 | #include 11 | 12 | bool 13 | havexft(void) { 14 | void *libxft; 15 | 16 | if(xft == nil) { 17 | libxft = dlopen("libXft.so", RTLD_LAZY); 18 | if(libxft == nil) 19 | return false; 20 | xft = emalloc(sizeof *xft); 21 | *(void**)(uintptr_t)&xft->drawcreate = dlsym(libxft, "XftDrawCreate"); 22 | *(void**)(uintptr_t)&xft->drawdestroy = dlsym(libxft, "XftDrawDestroy"); 23 | *(void**)(uintptr_t)&xft->fontopen = dlsym(libxft, "XftFontOpenXlfd"); 24 | *(void**)(uintptr_t)&xft->fontopenname = dlsym(libxft, "XftFontOpenName"); 25 | *(void**)(uintptr_t)&xft->fontclose = dlsym(libxft, "XftFontClose"); 26 | *(void**)(uintptr_t)&xft->textextents = dlsym(libxft, "XftTextExtentsUtf8"); 27 | *(void**)(uintptr_t)&xft->drawstring = dlsym(libxft, "XftDrawStringUtf8"); 28 | } 29 | return xft && xft->drawcreate && xft->drawdestroy && xft->fontopen 30 | && xft->fontopenname && xft->fontclose && xft->textextents && xft->drawstring; 31 | } 32 | 33 | #else 34 | bool 35 | havexft(void) { 36 | return false; 37 | } 38 | #endif 39 | 40 | -------------------------------------------------------------------------------- /lib/libutf/Makefile: -------------------------------------------------------------------------------- 1 | ROOT= ../.. 2 | include $(ROOT)/mk/hdr.mk 3 | 4 | VERSION=2.0 5 | TARG=libutf 6 | 7 | OBJ=\ 8 | rune\ 9 | runestrcat\ 10 | runestrchr\ 11 | runestrcmp\ 12 | runestrcpy\ 13 | runestrdup\ 14 | runestrlen\ 15 | runestrecpy\ 16 | runestrncat\ 17 | runestrncmp\ 18 | runestrncpy\ 19 | runestrrchr\ 20 | runestrstr\ 21 | runetype\ 22 | utfecpy\ 23 | utflen\ 24 | utfnlen\ 25 | utfrrune\ 26 | utfrune\ 27 | utfutf 28 | 29 | include $(ROOT)/mk/lib.mk 30 | 31 | -------------------------------------------------------------------------------- /lib/libutf/NOTICE: -------------------------------------------------------------------------------- 1 | This is a Unix port of the Plan 9 UTF-8 library, by Rob Pike and Ken Thompson. 2 | Please send comments about the packaging to Russ Cox . 3 | 4 | Copyright © 2021 Plan 9 Foundation 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /lib/libutf/README: -------------------------------------------------------------------------------- 1 | This software was packaged for Unix by Russ Cox. 2 | Please send comments to rsc@swtch.com. 3 | 4 | http://swtch.com/plan9port/unix 5 | 6 | -------------------------------------------------------------------------------- /lib/libutf/isalpharune.3: -------------------------------------------------------------------------------- 1 | .deEX 2 | .ift .ft5 3 | .nf 4 | .. 5 | .deEE 6 | .ft1 7 | .fi 8 | .. 9 | .TH ISALPHARUNE 3 10 | .SH NAME 11 | isalpharune, islowerrune, isspacerune, istitlerune, isupperrune, tolowerrune, totitlerune, toupperrune \- Unicode character classes and cases 12 | .SH SYNOPSIS 13 | .B #include 14 | .PP 15 | .B 16 | int isalpharune(Rune c) 17 | .PP 18 | .B 19 | int islowerrune(Rune c) 20 | .PP 21 | .B 22 | int isspacerune(Rune c) 23 | .PP 24 | .B 25 | int istitlerune(Rune c) 26 | .PP 27 | .B 28 | int isupperrune(Rune c) 29 | .PP 30 | .B 31 | Rune tolowerrune(Rune c) 32 | .PP 33 | .B 34 | Rune totitlerune(Rune c) 35 | .PP 36 | .B 37 | Rune toupperrune(Rune c) 38 | .SH DESCRIPTION 39 | These routines examine and operate on Unicode characters, 40 | in particular a subset of their properties as defined in the Unicode standard. 41 | Unicode defines some characters as alphabetic and specifies three cases: 42 | upper, lower, and title. 43 | Analogously to 44 | .IR isalpha (3) 45 | for 46 | .SM ASCII\c 47 | , 48 | these routines 49 | test types and modify cases for Unicode characters. 50 | The names are self-explanatory. 51 | .PP 52 | The case-conversion routines return the character unchanged if it has no case. 53 | .SH SOURCE 54 | .B http://swtch.com/plan9port/unix 55 | .SH "SEE ALSO 56 | .IR isalpha (3) , 57 | .IR "The Unicode Standard" . 58 | -------------------------------------------------------------------------------- /lib/libutf/libutf.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0intro/wmii/26848c93457606b350f57d6d313112a745a0cf3d/lib/libutf/libutf.a -------------------------------------------------------------------------------- /lib/libutf/runestrcat.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson. 3 | * Copyright (c) 2002 by Lucent Technologies. 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose without fee is hereby granted, provided that this entire notice 6 | * is included in all copies of any software which is or includes a copy 7 | * or modification of this software and in all copies of the supporting 8 | * documentation for such software. 9 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 10 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE 11 | * ANY REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY 12 | * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 13 | */ 14 | #include 15 | #include 16 | #include 17 | 18 | Rune* 19 | runestrcat(Rune *s1, const Rune *s2) 20 | { 21 | 22 | runestrcpy(runestrchr(s1, 0), s2); 23 | return s1; 24 | } 25 | -------------------------------------------------------------------------------- /lib/libutf/runestrchr.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson. 3 | * Copyright (c) 2002 by Lucent Technologies. 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose without fee is hereby granted, provided that this entire notice 6 | * is included in all copies of any software which is or includes a copy 7 | * or modification of this software and in all copies of the supporting 8 | * documentation for such software. 9 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 10 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE 11 | * ANY REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY 12 | * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 13 | */ 14 | #include 15 | #include 16 | #include "plan9.h" 17 | #include "utf.h" 18 | 19 | Rune* 20 | runestrchr(const Rune *s, Rune c) 21 | { 22 | Rune c0 = c; 23 | Rune c1; 24 | 25 | if(c == 0) { 26 | while(*s++) 27 | ; 28 | return (Rune*)s-1; 29 | } 30 | 31 | while(c1 = *s++) 32 | if(c1 == c0) 33 | return (Rune*)s-1; 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /lib/libutf/runestrcmp.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson. 3 | * Copyright (c) 2002 by Lucent Technologies. 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose without fee is hereby granted, provided that this entire notice 6 | * is included in all copies of any software which is or includes a copy 7 | * or modification of this software and in all copies of the supporting 8 | * documentation for such software. 9 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 10 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE 11 | * ANY REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY 12 | * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 13 | */ 14 | #include 15 | #include 16 | #include "plan9.h" 17 | #include "utf.h" 18 | 19 | int 20 | runestrcmp(const Rune *s1, const Rune *s2) 21 | { 22 | Rune c1, c2; 23 | 24 | for(;;) { 25 | c1 = *s1++; 26 | c2 = *s2++; 27 | if(c1 != c2) { 28 | if(c1 > c2) 29 | return 1; 30 | return -1; 31 | } 32 | if(c1 == 0) 33 | return 0; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /lib/libutf/runestrcpy.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson. 3 | * Copyright (c) 2002 by Lucent Technologies. 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose without fee is hereby granted, provided that this entire notice 6 | * is included in all copies of any software which is or includes a copy 7 | * or modification of this software and in all copies of the supporting 8 | * documentation for such software. 9 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 10 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE 11 | * ANY REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY 12 | * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 13 | */ 14 | #include 15 | #include 16 | #include "plan9.h" 17 | #include "utf.h" 18 | 19 | Rune* 20 | runestrcpy(Rune *s1, const Rune *s2) 21 | { 22 | Rune *os1; 23 | 24 | os1 = s1; 25 | while(*s1++ = *s2++) 26 | ; 27 | return os1; 28 | } 29 | -------------------------------------------------------------------------------- /lib/libutf/runestrdup.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson. 3 | * Copyright (c) 2002 by Lucent Technologies. 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose without fee is hereby granted, provided that this entire notice 6 | * is included in all copies of any software which is or includes a copy 7 | * or modification of this software and in all copies of the supporting 8 | * documentation for such software. 9 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 10 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE 11 | * ANY REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY 12 | * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 13 | */ 14 | #include 15 | #include 16 | 17 | Rune* 18 | runestrdup(const Rune *s) 19 | { 20 | Rune *ns; 21 | 22 | ns = malloc(sizeof(Rune)*(runestrlen(s) + 1)); 23 | if(ns == 0) 24 | return 0; 25 | 26 | return runestrcpy(ns, s); 27 | } 28 | -------------------------------------------------------------------------------- /lib/libutf/runestrecpy.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson. 3 | * Copyright (c) 2002 by Lucent Technologies. 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose without fee is hereby granted, provided that this entire notice 6 | * is included in all copies of any software which is or includes a copy 7 | * or modification of this software and in all copies of the supporting 8 | * documentation for such software. 9 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 10 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE 11 | * ANY REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY 12 | * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 13 | */ 14 | #include 15 | #include 16 | #include "plan9.h" 17 | #include "utf.h" 18 | 19 | Rune* 20 | runestrecpy(Rune *s1, Rune *es1, const Rune *s2) 21 | { 22 | if(s1 >= es1) 23 | return s1; 24 | 25 | while(*s1++ = *s2++){ 26 | if(s1 == es1){ 27 | *--s1 = '\0'; 28 | break; 29 | } 30 | } 31 | return s1; 32 | } 33 | -------------------------------------------------------------------------------- /lib/libutf/runestrlen.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson. 3 | * Copyright (c) 2002 by Lucent Technologies. 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose without fee is hereby granted, provided that this entire notice 6 | * is included in all copies of any software which is or includes a copy 7 | * or modification of this software and in all copies of the supporting 8 | * documentation for such software. 9 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 10 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE 11 | * ANY REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY 12 | * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 13 | */ 14 | #include 15 | 16 | long 17 | runestrlen(const Rune *s) 18 | { 19 | 20 | return runestrchr(s, 0) - s; 21 | } 22 | -------------------------------------------------------------------------------- /lib/libutf/runestrncat.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson. 3 | * Copyright (c) 2002 by Lucent Technologies. 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose without fee is hereby granted, provided that this entire notice 6 | * is included in all copies of any software which is or includes a copy 7 | * or modification of this software and in all copies of the supporting 8 | * documentation for such software. 9 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 10 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE 11 | * ANY REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY 12 | * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 13 | */ 14 | #include 15 | #include 16 | #include "plan9.h" 17 | #include "utf.h" 18 | 19 | Rune* 20 | runestrncat(Rune *s1, const Rune *s2, long n) 21 | { 22 | Rune *os1; 23 | 24 | os1 = s1; 25 | s1 = runestrchr(s1, 0); 26 | while(*s1++ = *s2++) 27 | if(--n < 0) { 28 | s1[-1] = 0; 29 | break; 30 | } 31 | return os1; 32 | } 33 | -------------------------------------------------------------------------------- /lib/libutf/runestrncmp.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson. 3 | * Copyright (c) 2002 by Lucent Technologies. 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose without fee is hereby granted, provided that this entire notice 6 | * is included in all copies of any software which is or includes a copy 7 | * or modification of this software and in all copies of the supporting 8 | * documentation for such software. 9 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 10 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE 11 | * ANY REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY 12 | * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 13 | */ 14 | #include 15 | #include 16 | #include "plan9.h" 17 | #include "utf.h" 18 | 19 | int 20 | runestrncmp(const Rune *s1, const Rune *s2, long n) 21 | { 22 | Rune c1, c2; 23 | 24 | while(n > 0) { 25 | c1 = *s1++; 26 | c2 = *s2++; 27 | n--; 28 | if(c1 != c2) { 29 | if(c1 > c2) 30 | return 1; 31 | return -1; 32 | } 33 | if(c1 == 0) 34 | break; 35 | } 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /lib/libutf/runestrncpy.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson. 3 | * Copyright (c) 2002 by Lucent Technologies. 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose without fee is hereby granted, provided that this entire notice 6 | * is included in all copies of any software which is or includes a copy 7 | * or modification of this software and in all copies of the supporting 8 | * documentation for such software. 9 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 10 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE 11 | * ANY REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY 12 | * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 13 | */ 14 | #include 15 | #include 16 | #include "plan9.h" 17 | #include "utf.h" 18 | 19 | Rune* 20 | runestrncpy(Rune *s1, const Rune *s2, long n) 21 | { 22 | int i; 23 | Rune *os1; 24 | 25 | os1 = s1; 26 | for(i = 0; i < n; i++) 27 | if((*s1++ = *s2++) == 0) { 28 | while(++i < n) 29 | *s1++ = 0; 30 | return os1; 31 | } 32 | return os1; 33 | } 34 | -------------------------------------------------------------------------------- /lib/libutf/runestrrchr.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson. 3 | * Copyright (c) 2002 by Lucent Technologies. 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose without fee is hereby granted, provided that this entire notice 6 | * is included in all copies of any software which is or includes a copy 7 | * or modification of this software and in all copies of the supporting 8 | * documentation for such software. 9 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 10 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE 11 | * ANY REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY 12 | * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 13 | */ 14 | #include 15 | #include 16 | #include "plan9.h" 17 | #include "utf.h" 18 | 19 | Rune* 20 | runestrrchr(const Rune *s, Rune c) 21 | { 22 | const Rune *r; 23 | 24 | if(c == 0) 25 | return runestrchr(s, 0); 26 | r = 0; 27 | while(s = runestrchr(s, c)) 28 | r = s++; 29 | return (Rune*)r; 30 | } 31 | -------------------------------------------------------------------------------- /lib/libutf/utfecpy.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson. 3 | * Copyright (c) 2002 by Lucent Technologies. 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose without fee is hereby granted, provided that this entire notice 6 | * is included in all copies of any software which is or includes a copy 7 | * or modification of this software and in all copies of the supporting 8 | * documentation for such software. 9 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 10 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE 11 | * ANY REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY 12 | * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 13 | */ 14 | #include 15 | #include 16 | #include "plan9.h" 17 | #include "utf.h" 18 | 19 | char* 20 | utfecpy(char *to, char *e, const char *from) 21 | { 22 | char *end; 23 | 24 | if(to >= e) 25 | return to; 26 | end = memccpy(to, from, '\0', e - to); 27 | if(end == nil){ 28 | end = e-1; 29 | while(end>to && (*--end&0xC0)==0x80) 30 | ; 31 | *end = '\0'; 32 | }else{ 33 | end--; 34 | } 35 | return end; 36 | } 37 | -------------------------------------------------------------------------------- /lib/libutf/utflen.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson. 3 | * Copyright (c) 2002 by Lucent Technologies. 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose without fee is hereby granted, provided that this entire notice 6 | * is included in all copies of any software which is or includes a copy 7 | * or modification of this software and in all copies of the supporting 8 | * documentation for such software. 9 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 10 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE 11 | * ANY REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY 12 | * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 13 | */ 14 | #include 15 | #include 16 | #include "plan9.h" 17 | #include "utf.h" 18 | 19 | int 20 | utflen(const char *s) 21 | { 22 | int c; 23 | long n; 24 | Rune rune; 25 | 26 | n = 0; 27 | for(;;) { 28 | c = *(uchar*)s; 29 | if(c < Runeself) { 30 | if(c == 0) 31 | return n; 32 | s++; 33 | } else 34 | s += chartorune(&rune, s); 35 | n++; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /lib/libutf/utfnlen.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson. 3 | * Copyright (c) 2002 by Lucent Technologies. 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose without fee is hereby granted, provided that this entire notice 6 | * is included in all copies of any software which is or includes a copy 7 | * or modification of this software and in all copies of the supporting 8 | * documentation for such software. 9 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 10 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE 11 | * ANY REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY 12 | * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 13 | */ 14 | #include 15 | #include 16 | #include "plan9.h" 17 | #include "utf.h" 18 | 19 | int 20 | utfnlen(const char *s, long m) 21 | { 22 | int c; 23 | long n; 24 | Rune rune; 25 | const char *es; 26 | 27 | es = s + m; 28 | for(n = 0; s < es; n++) { 29 | c = *(uchar*)s; 30 | if(c < Runeself){ 31 | if(c == '\0') 32 | break; 33 | s++; 34 | continue; 35 | } 36 | if(!fullrune(s, es-s)) 37 | break; 38 | s += chartorune(&rune, s); 39 | } 40 | return n; 41 | } 42 | -------------------------------------------------------------------------------- /lib/libwmii_hack/Makefile: -------------------------------------------------------------------------------- 1 | ROOT= ../.. 2 | include $(ROOT)/mk/hdr.mk 3 | 4 | hack.o hack.o_pic: util.c hack.h x11.h 5 | 6 | CFLAGS += $(INCX11) 7 | SOLDFLAGS += $(LIBX11) 8 | 9 | TARG = libwmii_hack 10 | # Can't just link libstuff here. We need PIC objects. 11 | OBJ = hack \ 12 | ../libstuff/util/getbase \ 13 | ../libstuff/util/getlong \ 14 | ../libstuff/util/tokenize 15 | 16 | include $(ROOT)/mk/so.mk 17 | 18 | -------------------------------------------------------------------------------- /lib/libwmii_hack/hack.h: -------------------------------------------------------------------------------- 1 | 2 | typedef unsigned long ulong; 3 | typedef unsigned int uint; 4 | typedef unsigned char uchar; 5 | 6 | #define _XOPEN_SOURCE 600 7 | #define IXP_P9_STRUCTS 8 | #define IXP_NO_P9_ 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | #define strdup my_strdup 19 | #define smprint my_smprint 20 | #define vsmprint my_vsmprint 21 | 22 | static char* smprint(const char*, ...); 23 | static char* vsmprint(const char*, va_list); 24 | static char* strdup(const char*); 25 | 26 | #define nil ((void*)0) 27 | #define nelem(ary) (sizeof(ary) / sizeof(*ary)) 28 | 29 | -------------------------------------------------------------------------------- /lib/libwmii_hack/util.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | static char* 6 | vsmprint(const char *fmt, va_list ap) { 7 | va_list al; 8 | char *buf = ""; 9 | int n; 10 | 11 | va_copy(al, ap); 12 | n = vsnprintf(buf, 0, fmt, al); 13 | va_end(al); 14 | 15 | buf = malloc(++n); 16 | if(buf) 17 | vsnprintf(buf, n, fmt, ap); 18 | return buf; 19 | } 20 | 21 | static char* 22 | smprint(const char *fmt, ...) { 23 | va_list ap; 24 | char *ret; 25 | 26 | va_start(ap, fmt); 27 | ret = vsmprint(fmt, ap); 28 | va_end(ap); 29 | return ret; 30 | } 31 | 32 | static char* 33 | strdup(const char *s) { 34 | char *ret; 35 | int len; 36 | 37 | len = strlen(s)+1; 38 | ret = malloc(len); 39 | if(ret) 40 | memcpy(ret, s, len); 41 | return ret; 42 | } 43 | 44 | -------------------------------------------------------------------------------- /lib/libwmii_hack/x11.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | static void changeprop_char(Display*, Window, char*, char*, char[], int); 6 | static void changeprop_long(Display*, Window, char*, char*, long[], int); 7 | /* static void changeprop_short(Display*, Window, char*, char*, short[], int); */ 8 | static void changeprop_string(Display*, Window, char*, char*); 9 | static void changeprop_textlist(Display*, Window, char*, char*, char*[]); 10 | static void changeproperty(Display*, Window, char*, char*, int width, uchar*, int); 11 | /* static void delproperty(Display*, Window, char*); */ 12 | /* static void freestringlist(char**); */ 13 | static ulong getprop_long(Display*, Window, char*, char*, ulong, long**, ulong); 14 | /* static char* getprop_string(Display*, Window, char*); */ 15 | /* static int getprop_textlist(Display*, Window, char*, char**[]); */ 16 | /* static ulong getproperty(Display*, Window, char*, char*, Atom*, ulong, uchar**, ulong); */ 17 | static Atom xatom(Display*, char*); 18 | 19 | -------------------------------------------------------------------------------- /man/Makefile: -------------------------------------------------------------------------------- 1 | ROOT=.. 2 | include $(ROOT)/mk/hdr.mk 3 | include $(ROOT)/mk/wmii.mk 4 | 5 | MANPAGES = wmii.1 \ 6 | wmiir.1 \ 7 | wmii9menu.1\ 8 | wihack.1 \ 9 | wimenu.1 \ 10 | wistrut.1 \ 11 | witray.1 12 | 13 | $(TARG): Makefile $(ROOT)/mk/wmii.mk header.t2t 14 | 15 | include $(ROOT)/mk/man.mk 16 | 17 | -------------------------------------------------------------------------------- /man/header.t2t: -------------------------------------------------------------------------------- 1 | %!target: man 2 | %!encoding: UTF-8 3 | 4 | % Special formatting for certain constructs. They, unfortunately 5 | % have to be post-processed. The _italic_ hack is necessary for 6 | % italicising things like /_foo_/, which txt2tags will ignore. 7 | % The others need to work in ``` lines. 8 | %!preproc(man): \bPROVISIONAL\b **PROVISIONAL** 9 | %!postproc(man): (<.*?>) \\fI\1\\fR 10 | %!postproc(man): \b_(.*?)_ \\fI\1\\fR 11 | %!postproc(man): \\e_ _ 12 | %!postproc(man): `(.*?)` \\fB\1\\fR 13 | %!postproc(man): \[(.*?)\] [\\fI\1\\fR] 14 | %!postproc(man): \+$ \n.P 15 | %!postproc(man): (\$[a-zA-Z_]+) \\fB\1\\fR 16 | %!postproc(man): (\${[a-zA-Z_]+)(.*?)} \\fB\1\\fR\2\\fB}\\fR 17 | 18 | %!postproc(html): (<.*?>) (:arg \1:) 19 | %!postproc(html): \b_(.*?)_ (:emph \1:) 20 | %!postproc(html): `(.*?)` (:code \1:) 21 | %!postproc(html): \+$
22 | 23 | %!postproc(html) \(:(\w+)\s*(.*):\) \2 24 | 25 | % Well, it seems that txt2tags isn't particularly well suited 26 | % to troff output. These two hacks make multi-level definition 27 | % lists possible. 28 | %!postproc(man): ^\s*>>$ .RS 8 29 | %!postproc(man): ^\s*<<$ .RS -8 30 | 31 | %!postproc(html): ^\s*>>$ 32 | %!postproc(html): ^\s*<<$ 33 | 34 | -------------------------------------------------------------------------------- /man/mkfile: -------------------------------------------------------------------------------- 1 | TARG = `{bmake -VTARG} 2 | 3 | default:V: all 4 | 5 | all:V: $TARG 6 | 7 | %.1: %.tex 8 | latex2man -M $stem.tex $stem.1 9 | 10 | -------------------------------------------------------------------------------- /mk/common.mk: -------------------------------------------------------------------------------- 1 | all: 2 | 3 | install: all simpleinstall 4 | uninstall: simpleuninstall 5 | 6 | DOCDIR = $(DOC) 7 | simpleinstall: 8 | for f in $(DOCS); do \ 9 | $(INSTALL) 0644 $$f $(DOCDIR) $$f; \ 10 | done 11 | for f in $(TEXT); do \ 12 | $(INSTALL) 0644 $$f $(DIR) $$f; \ 13 | done 14 | for f in $(BINARY); do \ 15 | $(INSTALL) -b 0644 $$f $(DIR) $$f; \ 16 | done 17 | for f in $(EXECS); do \ 18 | $(INSTALL) 0755 $$f $(DIR) $$f; \ 19 | done 20 | 21 | simpleuninstall: 22 | for f in $(DOCS); do \ 23 | $(UNINSTALL) $$f $(DOCDIR) $$f; \ 24 | done 25 | for f in $(TEXT); do \ 26 | $(UNINSTALL) $$f $(DIR) $$f; \ 27 | done 28 | for f in $(BINARY); do \ 29 | $(UNINSTALL) -b $$f $(DIR) $$f; \ 30 | done 31 | for f in $(EXECS); do \ 32 | $(UNINSTALL) -b $$f $(DIR) $$f; \ 33 | done 34 | 35 | cleandep: 36 | echo CLEANDEP 37 | rm .depend 2>/dev/null || true 38 | 39 | tags: 40 | files=; \ 41 | for f in $(OBJ); do \ 42 | [ -f "$$f.c" ] && files="$$files $$f.c"; \ 43 | done; \ 44 | echo CTAGS $$files $(TAGFILES); \ 45 | if [ -n "$$files" ]; then $(DEBUG) $(CTAGS) $$files $(TAGFILES); fi 46 | 47 | .PHONY: all options clean dist install uninstall depend cleandep tags 48 | .PHONY: simpleuninstall simpleinstall 49 | -------------------------------------------------------------------------------- /mk/dir.mk: -------------------------------------------------------------------------------- 1 | MKSUBDIR = \ 2 | set -e; \ 3 | targ=$@; targ=$${targ\#d}; \ 4 | for i in $$dirs; do \ 5 | export $(SUBMAKE_EXPORT) BASE=$(BASE)$$i/; \ 6 | if [ ! -d $$i ]; then \ 7 | echo Skipping nonexistent directory: $$i 1>&2; \ 8 | else \ 9 | echo MAKE $$targ $$BASE; \ 10 | (cd $$i && $(MAKE) $$targ) || exit $?; \ 11 | fi; \ 12 | done 13 | 14 | dall: 15 | +dirs="$(DIRS)"; $(MKSUBDIR) 16 | dclean: 17 | +dirs="$(DIRS)"; $(MKSUBDIR) 18 | dinstall: 19 | +dirs="$(INSTDIRS)"; $(MKSUBDIR) 20 | duninstall: 21 | +dirs="$(INSTDIRS)"; $(MKSUBDIR) 22 | ddepend: 23 | +dirs="$(DIRS)"; $(MKSUBDIR) 24 | dtags: 25 | +dirs="$(DIRS)"; $(MKSUBDIR) 26 | 27 | all: dall 28 | clean: dclean 29 | install: dinstall 30 | uninstall: duninstall 31 | depend: ddepend 32 | tags: dtags 33 | 34 | INSTDIRS = $(DIRS) 35 | 36 | -------------------------------------------------------------------------------- /mk/gcc.mk: -------------------------------------------------------------------------------- 1 | DEBUGCFLAGS = \ 2 | -g \ 3 | -O0 \ 4 | -fno-builtin \ 5 | -fno-inline \ 6 | -fno-omit-frame-pointer \ 7 | -fno-optimize-sibling-calls \ 8 | -fno-unroll-loops 9 | CFLAGS += \ 10 | -std=c99 \ 11 | -pedantic \ 12 | -pipe \ 13 | -fno-strict-aliasing \ 14 | -Wall \ 15 | -Wimplicit \ 16 | -Wmissing-prototypes \ 17 | -Wno-comment \ 18 | -Wno-missing-braces \ 19 | -Wno-parentheses \ 20 | -Wno-sign-compare \ 21 | -Wno-switch \ 22 | -Wpointer-arith \ 23 | -Wreturn-type \ 24 | -Wstrict-prototypes \ 25 | -Wtrigraphs 26 | MKDEP = cpp -M 27 | SOCFLAGS += -fPIC 28 | 29 | -------------------------------------------------------------------------------- /mk/lib.mk: -------------------------------------------------------------------------------- 1 | PTARG = $(ROOT)/lib/$(TARG) 2 | LIB = $(PTARG).a 3 | OFILES = $(OBJ:=.o) 4 | 5 | all: $(HFILES) $(LIB) 6 | 7 | install: $(PTARG).install 8 | uninstall: $(PTARG).uninstall 9 | clean: libclean 10 | depend: $(OBJ:=.depend) 11 | 12 | libclean: 13 | for i in $(LIB) $(OFILES); do \ 14 | [ -e $$i ] && \ 15 | echo CLEAN $$($(CLEANNAME) $(BASE)$$i); \ 16 | rm -f $$i; \ 17 | done 2>/dev/null || true 18 | 19 | printinstall: 20 | echo 'Install directories:' 21 | echo ' Lib: $(LIBDIR)' 22 | 23 | $(LIB): $(OFILES) 24 | echo AR $$($(CLEANNAME) $(BASE)/$@) 25 | mkdir $(ROOT)/lib 2>/dev/null || true 26 | $(AR) $@ $(OFILES) 27 | 28 | SOMKSH=case "$(MAKESO)" in 1|[Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]) echo $(ROOT)/mk/so.mk;; *) echo /dev/null;; esac 29 | SOMK:=$(shell $(SOMKSH)) 30 | SOMK!=$(SOMKSH) 31 | include $(SOMK) 32 | 33 | -------------------------------------------------------------------------------- /mk/man.mk: -------------------------------------------------------------------------------- 1 | 2 | targ = for k in $(MANPAGES); do echo $$k | sed 's/ .*//'; done 3 | TARG:= $(shell $(targ)) 4 | TARG!= $(targ) 5 | 6 | all: $(TARG) 7 | install: $(TARG:.1=.install) $(TARG:.3=.install) maninstall 8 | uninstall: $(TARG:.1=.uninstall) $(TARG:.3=.uninstall) manuninstall 9 | 10 | .PHONY: maninstall manuninstall 11 | 12 | MANLOOP = \ 13 | set -ef; \ 14 | for k in $(MANPAGES); do \ 15 | set -- $$k; \ 16 | real=$$1; shift; \ 17 | for targ; do \ 18 | _ $$real $(MAN)/man$${real\#\#*.}/$$targ; \ 19 | done; \ 20 | done 21 | maninstall: 22 | _() { echo LN $$1 $${2##*/}; ln -sf $$1 $(DESTDIR)$$2; }; $(MANLOOP) 23 | manuninstall: 24 | _() { echo RM $${2##*/}; rm -f $(DESTDIR)$$2; }; $(MANLOOP) 25 | 26 | printinstall: 27 | echo 'Install directories:' 28 | echo ' Man: $(MAN)' 29 | 30 | -------------------------------------------------------------------------------- /mk/many.mk: -------------------------------------------------------------------------------- 1 | PROGS = $(TARG:=.out) 2 | 3 | all: $(OFILES) $(PROGS) 4 | 5 | install: $(TARG:=.install) 6 | uninstall: $(TARG:=.uninstall) 7 | depend: $(OFILES:.o=.depend) $(TARG:=.depend) 8 | clean: manyclean 9 | 10 | printinstall: 11 | echo 'Install directories:' 12 | echo ' Bin: $(BIN)' 13 | 14 | manyclean: 15 | for i in $(TARG:=.o) $(TARG:=.out) $(OFILES); do \ 16 | [ -e $$i ] && \ 17 | echo CLEAN $$($(CLEANNAME) $(BASE)$$i); \ 18 | rm -f $$i; \ 19 | done 2>/dev/null || true 20 | 21 | -------------------------------------------------------------------------------- /mk/one.mk: -------------------------------------------------------------------------------- 1 | PROG = $(TARG).out 2 | OFILES = $(OBJ:=.o) 3 | 4 | all: $(PROG) 5 | 6 | install: $(TARG).install 7 | uninstall: $(TARG).uninstall 8 | clean: oneclean 9 | depend: $(OBJ:=.depend) 10 | 11 | printinstall: 12 | echo 'Install directories:' 13 | echo ' Bin: $(BIN)' 14 | 15 | oneclean: 16 | for i in $(PROG) $(OFILES); do \ 17 | [ -e $$i ] && \ 18 | echo CLEAN $$($(CLEANNAME) $(BASE)$$i); \ 19 | rm -f $$i; \ 20 | done 2>/dev/null || true 21 | 22 | $(OFILES): $(HFILES) 23 | 24 | $(PROG): $(OFILES) $(LIB) 25 | $(LINK) $@ $(OFILES) $(LIB) 26 | 27 | -------------------------------------------------------------------------------- /mk/python.mk: -------------------------------------------------------------------------------- 1 | 2 | # all: pybuild 3 | install: $(PYMODULES:%=%.install) 4 | clean: pyclean 5 | 6 | .py.install: 7 | echo PYTHON install $* $(PYPREFIX) 8 | DESTDIR=$(DESTDIR); \ 9 | $(DEBUG) $(PYTHON) $< install -c --root=$${DESTDIR:-/} $(PYPREFIX) 10 | pyclean: 11 | echo CLEAN build/ 12 | rm -rf build 13 | 14 | .PHONY: pybuild pyclean 15 | -------------------------------------------------------------------------------- /mk/so.mk: -------------------------------------------------------------------------------- 1 | SOPTARG = $(ROOT)/lib/$(TARG) 2 | SO = $(SOPTARG).$(SOEXT) 3 | SONAME = $(TARG).$(SOEXT) 4 | OFILES_PIC = $(OBJ:=.o_pic) 5 | 6 | all: $(HFILES) $(SO) 7 | 8 | install: $(SOPTARG).install 9 | uninstall: $(SOPTARG).uninstall 10 | clean: soclean 11 | depend: $(OBJ:=.depend) 12 | 13 | soclean: 14 | for i in $(SO) $(OFILES_PIC); do \ 15 | [ -e $$i ] && \ 16 | echo CLEAN $$($(CLEANNAME) $(BASE)$$i); \ 17 | rm -f $$i; \ 18 | done 2>/dev/null || true 19 | 20 | printsoinstall: 21 | echo 'Install directories:' 22 | echo ' Lib: $(LIBDIR)' 23 | 24 | printinstall: printsoinstall 25 | 26 | $(SO): $(OFILES_PIC) 27 | mkdir $(ROOT)/lib 2>/dev/null || true 28 | $(LINKSO) $@ $(OFILES_PIC) 29 | 30 | -------------------------------------------------------------------------------- /rc/Makefile: -------------------------------------------------------------------------------- 1 | ROOT=.. 2 | include $(ROOT)/mk/hdr.mk 3 | include $(ROOT)/mk/wmii.mk 4 | 5 | BIN = $(GLOBALCONF) 6 | TARG = wmiirc \ 7 | welcome 8 | 9 | include $(ROOT)/mk/many.mk 10 | -------------------------------------------------------------------------------- /test/Makefile: -------------------------------------------------------------------------------- 1 | ROOT=.. 2 | include $(ROOT)/mk/hdr.mk 3 | 4 | TARG = grav 5 | 6 | OFILES = ../cmd/util.o \ 7 | ../cmd/wmii/map.o \ 8 | ../cmd/wmii/x11.o 9 | 10 | LDFLAGS += $(OFILES) -lfmt -lutf -lbio $(LIBX11) -lXext 11 | CFLAGS += $(INCX11) 12 | 13 | include $(ROOT)/mk/many.mk 14 | 15 | -------------------------------------------------------------------------------- /test/event: -------------------------------------------------------------------------------- 1 | #!/bin/rc 2 | 3 | wm='' 4 | if(~ $1 -d) { 5 | wm = '&wm/wm wm/logon 0 && a[n] != "..") 9 | n-- 10 | else if($i != "" && $i != ".") 11 | a[++n] = $i 12 | } 13 | s = "" 14 | for(i = 1; i <= n; i++) 15 | s = s "/" a[i] 16 | print substr(s, 2) 17 | }' 18 | 19 | -------------------------------------------------------------------------------- /util/genchangelog: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -ef 3 | 4 | ifs="$(echo)" 5 | name=$1 6 | vers=$2 7 | dist=$3 8 | desc="Upstream build" 9 | auth="Kris Maglione " 10 | date=$(date +'%a, %d %b %Y %T %z') 11 | if hg root >/dev/null 2>&1; then 12 | t() { hg log -r . --template "{$@}"; } 13 | vers=$(t rev) 14 | desc=$(t desc) 15 | auth=$(t author) 16 | date=$(t 'date|rfc822date') 17 | fi 18 | 19 | cat >debian/changelog.new <$xtmp 2>&1 32 | status=$? 33 | [ $status -eq 0 ] || echo $LD -o $outfile $ofiles $LDFLAGS $args >&2 34 | 35 | sed 's/.*: In function `[^:]*: *//' $xtmp | grep -E . | 36 | grep -E -v 'is almost always misused|is dangerous, better use|in statically linked applications requires at runtime' 37 | rm -f $xtmp 38 | 39 | exit $status 40 | 41 | --------------------------------------------------------------------------------