---------------------------------------------------------------1-- Basic scratchpad manager for the awesome window manager2---------------------------------------------------------------3-- Coded by: Adrian C. <[email protected]>4-- Licensed under the WTFPL version 25-- * http://sam.zoy.org/wtfpl/COPYING6---------------------------------------------------------------7-- To use this module add:8-- require("scratchpad")9-- to the top of your rc.lua, and call:10-- scratchpad.set(c, width, height, sticky, screen)11-- from a clientkeys binding, and:12-- scratchpad.toggle(screen)13-- from a globalkeys binding.14--15-- Parameters:16-- c - Client to scratch or un-scratch17-- width - Width in absolute pixels, or width percentage18-- when <= 1 (0.50 (50% of the screen) by default)19-- height - Height in absolute pixels, or height percentage20-- when <= 1 (0.50 (50% of the screen) by default)21-- sticky - Visible on all tags, false by default22-- screen - Screen (optional), mouse.screen by default23---------------------------------------------------------------2425-- Grab environment26local awful = require("awful")27local capi = {28mouse = mouse,29client = client,30screen = screen31}3233-- Scratchpad: Basic scratchpad manager for the awesome window manager34module("scratchpad")3536local scratch = {}3738-- Toggle a set of properties on a client.39local function toggleprop(c, prop)40c.ontop = prop.ontop or false41c.above = prop.above or false42c.hidden = prop.hidden or false43c.sticky = prop.stick or false44c.skip_taskbar = prop.task or false45end4647-- Scratch the focused client, or un-scratch and tile it. If another48-- client is already scratched, replace it with the focused client.49function set(c, width, height, sticky, screen)50local width = width or 0.5051local height = height or 0.5052local sticky = sticky or false53local screen = screen or capi.mouse.screen5455local function setscratch(c)56-- Scratchpad is floating and has no titlebar57awful.client.floating.set(c, true); awful.titlebar.remove(c)5859-- Scratchpad client properties60toggleprop(c, {ontop=true, above=true, task=true, stick=sticky})6162-- Scratchpad geometry and placement63local screengeom = capi.screen[screen].workarea64if width <= 1 then width = screengeom.width * width end65if height <= 1 then height = screengeom.height * height end6667c:geometry({ -- Scratchpad is always centered on screen68x = screengeom.x + (screengeom.width - width) / 2,69y = screengeom.y + (screengeom.height - height) / 2,70width = width, height = height71})7273-- Scratchpad should not loose focus74c:raise(); capi.client.focus = c75end7677-- Prepare a table for storing clients,78if not scratch.pad then scratch.pad = {}79-- add unmanage signal for scratchpad clients80capi.client.add_signal("unmanage", function (c)81if scratch.pad[screen] == c then82scratch.pad[screen] = nil83end84end)85end8687-- If the scratcphad is emtpy, store the client,88if not scratch.pad[screen] then89scratch.pad[screen] = c90-- then apply geometry and properties91setscratch(c)92else -- If a client is already scratched,93local oc = scratch.pad[screen]94-- unscratch, and compare it with the focused client95awful.client.floating.toggle(oc); toggleprop(oc, {})96-- If it matches clear the table, if not replace it97if oc == c then scratch.pad[screen] = nil98else scratch.pad[screen] = c; setscratch(c) end99end100end101102-- Move the scratchpad to the current workspace, focus and raise it103-- when it's hidden, or hide it when it's visible.104function toggle(screen)105local screen = screen or capi.mouse.screen106107-- Check if we have a client on storage,108if scratch.pad and109scratch.pad[screen] ~= nil110then -- and get it out, to play111local c = scratch.pad[screen]112113-- If it's visible on another tag hide it,114if c:isvisible() == false then c.hidden = true115-- and move it to the current worskpace116awful.client.movetotag(awful.tag.selected(screen), c)117end118119-- Focus and raise if it's hidden,120if c.hidden then121awful.placement.centered(c)122c.hidden = false123c:raise(); capi.client.focus = c124else -- hide it if it's not125c.hidden = true126end127end128end129130131