Last active
December 14, 2015 03:39
-
-
Save lionicsheriff/5022331 to your computer and use it in GitHub Desktop.
Kindle Touch: Remap home button to next page. Requires xdotool While reading, reject touch events. Can be overriden by holding down home
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Copyright (c) 2011 Amazon Technologies, Inc. All rights reserved. | |
-- PROPRIETARY/CONFIDENTIAL | |
-- Use is subject to license terms. | |
require("awful") | |
require("awful.rules") | |
-- local copy of the screen | |
g_screenOne = screen[1] | |
--lab126 libraries | |
require("lab126_logging") | |
require("lab126LayerLogic") | |
require("lab126_chrome_layer") | |
require("lab126_screensaver_layer") | |
require("lab126_dialog_layer") | |
require("lab126_keyboard_layer") | |
require("lab126_application_layer") | |
require("lab126_orientation") | |
require("lab126_ew") | |
require("lab126_ligl") | |
require("liblipclua") | |
-- Configure garbage collector to start when total memory in use increases by 25% | |
local oldGcPause = collectgarbage("setpause", 125) | |
log("collectgarbage.pause = 125. Was " .. tostring(oldGcPause)) | |
local lipcH, errNum, errMsg = lipc.init("com.lab126.winmgr") | |
if not lipcH then | |
log ("!!!!!!!!!!!failed to init lipc " .. tostring(errNum) .. ", " .. errMsg) | |
else | |
lipc.set_error_handler(logErrorAndStackTrace) | |
end | |
registerOrientationProperties(lipcH) | |
chrome_register_properties(lipcH) | |
dialog_events_setup(lipcH) | |
-- Default modkey. | |
-- Usually, Mod4 is the key with a logo between Control and Alt. | |
-- If you do not like this or do not have such a key, | |
-- I suggest you to remap Mod4 to another key using xmodmap or other tools. | |
-- However, you can use another modifier like Mod1, but it may interact with others. | |
modkey = "Mod4" | |
-- Table of layouts to cover with awful.layout.inc, order matters. | |
layouts = | |
{ | |
awful.layout.suit.floating, | |
awful.layout.suit.tile, | |
awful.layout.suit.tile.left, | |
awful.layout.suit.tile.bottom, | |
awful.layout.suit.tile.top, | |
awful.layout.suit.fair, | |
awful.layout.suit.fair.horizontal, | |
awful.layout.suit.spiral, | |
awful.layout.suit.spiral.dwindle, | |
awful.layout.suit.max, | |
awful.layout.suit.max.fullscreen, | |
awful.layout.suit.magnifier | |
} | |
-- }}} | |
-- single window, two tags | |
globalTag = awful.tag({ 1, 2 }, 1, layouts[1]) | |
-- layering window of current application | |
g_activeApplicationWindow = nil | |
-- Awesome client currently assosiated with a keyboard | |
g_keyboardDialogClient = nil | |
local s_homeKeyDownState = { | |
isDown = false, | |
timeStamp = 0 | |
} | |
local s_controlClient = nil | |
--[[ | |
set lipc property/value to pub | |
]]-- | |
function setLipcProp(pub, prop, value) | |
lipcH:set_string_property(pub, prop, value) | |
end | |
function sendLipcEvent(event, values) | |
lipcH:send_event(event, values) | |
end | |
--- Update active application window | |
-- If client's name has "L:A_N:application" and active application is different, | |
-- set active application window to client | |
-- @param c Client | |
local function updateActiveApplicationWindow(c) | |
local appWindow = windowTableFindByClient(c) | |
-- check to see if application is already the g_activeApplicationWindow | |
if appWindow and application_is_application_window(appWindow) and | |
(not g_activeApplicationWindow or g_activeApplicationWindow.c ~= c) then | |
log("active application is different") | |
application_update_active_app_window(appWindow) | |
end | |
end | |
--[[ | |
get drawmode from client and set ligl | |
]]-- | |
function setDrawModeAndSensitivity() | |
log("+++++setDrawModeAndSensitivity") | |
if not s_controlClient then | |
return | |
end | |
local c = s_controlClient | |
local window = windowTableFindByClient(c) | |
if not window or not window.params then | |
return | |
end | |
local dm = window.params.DM or "N" | |
liglSetDrawMode(dm, c:geometry()) | |
local sensitivity = -1 | |
-- Apply sensitivity only if draw mode is normal | |
if dm == "N" then | |
-- EWH hosts defer to the sensitivity of their | |
-- EWC client | |
if window.params.EWH then | |
log("============= EWH in control") | |
local ewc = ew_get_client(window) | |
if ewc then | |
log("setting sens to client's value'") | |
sensitivity = tonumber(ewc.params.S) | |
end | |
else | |
sensitivity = tonumber(window.params.S) | |
end | |
end | |
if sensitivity ~= nil then | |
log("sending sensitivity value " .. tostring(sensitivity)) | |
liglSetSensitive(sensitivity, c:geometry()) | |
else | |
-- ligl uses -1 to mean off | |
log("no sensitivity value, send -1") | |
liglSetSensitive(-1, c:geometry()) | |
end | |
end | |
--[[ | |
called when geometry has changed on a control client | |
]]-- | |
local function updateControlWindowGeometry() | |
if not s_controlClient then | |
return | |
end | |
setDrawModeAndSensitivity() | |
end | |
--[[ | |
called when name changes on control client | |
]]-- | |
local function updateControlWindowName() | |
if not s_controlClient then | |
return | |
end | |
setDrawModeAndSensitivity() | |
end | |
--[[ | |
called when the control client changes via focus change or user | |
tap | |
@ c | |
new control client | |
]]-- | |
local function setControlClient(c) | |
log("+++++setControlClient ") | |
if s_controlClient == c then | |
return | |
end | |
if not c or not c.name then | |
return | |
end | |
if s_controlClient then | |
logStrings({"control window changing from ", s_controlClient.name}) | |
end | |
logStrings({"control window changing to ", c.name}) | |
s_controlClient = c | |
setDrawModeAndSensitivity() | |
end | |
--[[ | |
sets the focused to the new client | |
c : client to switch focus to | |
]]-- | |
function setFocusedClient(c) | |
if not c then | |
log("setFocusedClient called with bad client") | |
return | |
end | |
-- try this to see if it helps wit the phantom focus lose | |
if c == client.focus then | |
log("client already has focus") | |
end | |
local window = windowTableFindByClient(c) | |
if not window or not window.params then | |
return | |
end | |
if window.params.HIDE == "background" then | |
log("backgrounded windows dont take focus") | |
return | |
end | |
-- if client does not accept focus then | |
-- bail | |
if c.nofocus then | |
log("client does not accept focus") | |
-- set as control window even if | |
-- it does not take focus. | |
setControlClient(c) | |
return | |
end | |
--[[ | |
If client is a screensaver, focus it. | |
If there is a screensaver, insert client into the focus history | |
before the first screensaver but do not focus it. | |
If there are no screensavers, focus client. | |
]]-- | |
local ssCount = 0 | |
local pillowAlertCount = 0 | |
if window.params.L ~= "SS" then | |
for i, v in ipairs(awful.client.data.focus) do | |
-- still a little quicker in the loop to use a | |
-- starts with rather than look up client | |
if stringStartsWith(v.name, "L:SS") then | |
ssCount = ssCount + 1 | |
else | |
break | |
end | |
end | |
-- look for a non hidden pillow alert | |
local existingAlert = findWindow("D", "pillowAlert") | |
if window.params.N ~= "pillowAlert" and existingAlert and not existingAlert.c.hiddenLayer then | |
pillowAlertCount = 1 | |
end | |
end | |
if ssCount > 0 or pillowAlertCount > 0 then | |
if awful.client.focus.filter(c) then | |
-- Remove the client if its already there | |
awful.client.focus.history.delete(c) | |
-- Insert client into focus history | |
table.insert(awful.client.data.focus, ssCount + pillowAlertCount + 1, c) | |
end | |
-- Although window is not focused update active application window if needed | |
updateActiveApplicationWindow(c) | |
else | |
-- change the focus | |
logStrings({"=====focus set to : ", c.name}) | |
awful.client.focus.history.add(c) | |
client.focus = c | |
end | |
end | |
-- when we change geometry on a client | |
-- set it here such that the geometry change | |
-- callback can be identified as a result of | |
-- an external or internal request | |
local s_geometryChangingClient = nil | |
--[[ | |
changes window geometry | |
w : window to act on | |
newGeometry : geometry object with x, y, width and height | |
]]-- | |
function changeWindowGeometry(w, newGeometry) | |
if not w or not w.c or not newGeometry then | |
log("!!changeWindowGeometry called with invalid window") | |
end | |
logStrings({"changeWindowGeometry w.c.name = ", w.c.name}) | |
log("changeWindowGeometry newGeometry = " .. newGeometry.x .. " " .. newGeometry.y .. | |
" " .. newGeometry.width .. " " .. newGeometry.height) | |
-- store new geometry | |
if not w.geometry then | |
w.geometry = {} | |
end | |
w.geometry.x = newGeometry.x | |
w.geometry.y = newGeometry.y | |
w.geometry.width = newGeometry.width | |
w.geometry.height = newGeometry.height | |
-- set s_geometryChangingClient as noted above | |
s_geometryChangingClient = w.c | |
-- change geometry | |
w.c:geometry(newGeometry) | |
-- done, clear state | |
s_geometryChangingClient = nil | |
end | |
--[[ | |
returns geometry of client | |
c : client to act on | |
]]-- | |
function getClientGeometry(c) | |
return c:geometry() | |
end | |
-- Z Stack Layers matching | |
-- internal layers in Awesome | |
-- 0 and 1 are used by awesome | |
-- and we do not use them here | |
LAYERS = {} | |
LAYERS.HIDDEN = 2 -- hidden | |
LAYERS.BLANK = 3 -- below | |
LAYERS.APP = 4 -- normal | |
LAYERS.CHROME = 5 -- above | |
LAYERS.DIALOG = 6 -- dialog | |
LAYERS.KB = 7 -- KB | |
LAYERS.ALERT = 8 -- ALERT | |
LAYERS.FULL = 9 -- FULL, not used | |
LAYERS.SCREENSAVER = 10 -- ontop | |
--[[ | |
sets client c's z stack layer in awesome | |
note that this differs from calling | |
c->hiddenLayer = true in that this is a sync | |
operation. The latter | |
]]-- | |
function setClientLayer(win, newZStackLayer) | |
-- check for HIDE flag override | |
local layerTo | |
if win.params and win.params.HIDE then | |
layerTo = LAYERS.HIDDEN | |
else | |
layerTo = newZStackLayer | |
end | |
if win and win.c then | |
if layerTo == LAYERS.HIDDEN and not win.c.hiddenLayer then | |
visibilityChanged(win, false) | |
elseif layerTo ~= LAYERS.HIDDEN and win.c.hiddenLayer then | |
visibilityChanged(win, true) | |
end | |
win.c:set_layer_without_restack(layerTo) | |
end | |
end | |
--[[ | |
look up a client by layerName and name and set Z stack order | |
]]-- | |
function findAndSetClientLayer(layerName, name, newZStackLayer) | |
setClientLayer(findWindow(layerName, name), newZStackLayer) | |
end | |
--[[ | |
prints out various info oncurrent windows for debugging purposes | |
]]-- | |
function print_dbg_info() | |
log("+++++print_dbg_info") | |
local tagTable = g_screenOne:tags() | |
print_table_contents("tagTable", tagTable, "") | |
-- print out all clients and their geometry | |
--[[ | |
local allClients = client.get(1) | |
for i,c in ipairs(allClients) do | |
logStrings({"client : ", c.name}) | |
print_table_contents("clientGeometry", c:geometry(), "") | |
end | |
]]-- | |
logOutAllLayers() | |
if client.focus then | |
logStrings({"current focus is ", client.focus.name}) | |
else | |
log("no focus") | |
end | |
end | |
--[[ | |
prints out current focus stack for debugging | |
]]-- | |
function dumpFocusInfo() | |
if client.focus then | |
logStrings({"focused client is ", client.focus.name}) | |
else | |
log("no focused client") | |
end | |
local idx = 0 | |
local lastClient = nil | |
repeat | |
local nextClient = awful.client.focus.history.get (1, idx) | |
if nextClient then | |
logStrings({"next focus client ", nextClient.name}) | |
end | |
if nextClient == lastClient then | |
logStrings({"nextClient is lastClient ", lastClient.name}) | |
break | |
end | |
lastClient = nextClient | |
idx = idx + 1 | |
until not nextClient | |
end | |
-- register a dbg property to open up additional debug | |
-- info calls | |
local s_debugInfo = lipcH:register_string_property("debugInfo", "rw") | |
s_debugInfo.value = "" | |
s_debugInfo.listener = function (name, value) | |
if value == "dumpFocusStack" then | |
dumpFocusInfo() | |
elseif value == "drawMode" then | |
logDrawMode() | |
if s_controlClient and s_controlClient.name then | |
logStrings({"control window is ", s_controlClient.name}) | |
else | |
log("no control window") | |
end | |
elseif value == "luaMem" then | |
log("Lua memory is " .. collectgarbage("count") .. " Kbytes") | |
elseif value == "luaGC" then | |
collectgarbage("collect") | |
elseif value == "forceRestack" then | |
client.force_restack() | |
elseif value == "logAllClients" then | |
client.log_all_clients() | |
elseif value == "validateStack" then | |
client.validate_stacking_order() | |
end | |
end | |
-- register a property to turn on 2 finger tap chrome twoFingerTapChrome | |
local s_altChrome = lipcH:register_int_property("altChrome", "rw") | |
s_altChrome.value = 0 | |
--[[ | |
handles the press of homekey and call appmgrd | |
]]-- | |
local s_blockHome = false | |
local s_forceTap = false | |
function handleHomeKeyUp() | |
log("received home key") | |
local homeKeyDownDuration = os.time() - s_homeKeyDownState.timeStamp | |
-- clear state | |
s_homeKeyDownState.isDown = false | |
s_homeKeyDownState.timeStamp = 0 | |
if s_blockHome == true then | |
s_blockHome = false | |
return | |
end | |
if s_homeKeyDownState.screenShotTaken then | |
s_homeKeyDownState.screenShotTaken = false | |
llog.info("WindowManager", "tapHandledByWinMgr", "ID=HomeKeyUp, reason=screenShot", "") | |
return | |
end | |
-- if the home key was used for a home key combo or screen saver is up then dont launch home | |
if not findWindow("SS", "screenSaver") then | |
if s_altChrome.value == 2 then | |
-- s_altChrome of 2 uses home button to bring up | |
-- and lower chrome | |
if chrome_is_up() then | |
chrome_lower() | |
else | |
chrome_raise() | |
-- because this is just demo code I am using | |
-- a bit of a hack to work around the focus | |
-- problem I see after we raise chrome on | |
-- home button | |
-- TODO if this method becomes POR then | |
-- take the hack out | |
s_tempHackToStopFocusAfterChromeRaise = true | |
end | |
else | |
if lipcH then | |
chrome_lower() | |
local blockHomeButton = false | |
local inReader = false | |
if client.focus then | |
local focusedWin = windowTableFindByClient(client.focus) | |
inReader = focusedWin.params.ID == "com.lab126.booklet.reader" | |
if focusedWin.params.L == "D" and focusedWin.params.N == "pillowAlert" then | |
llog.info("WindowManager", "homeKeyBlocked", "reason=alertIsVisible", "") | |
blockHomeButton = true | |
end | |
end | |
if not blockHomeButton then | |
if homeKeyDownDuration > 1 or not inReader then | |
-- launch the default app | |
log("==============Sending Home Button") | |
logTimeStamp("home button press") | |
client.validate_stacking_order() | |
lipcH:set_int_property("com.lab126.appmgrd", "startdefault", 0) | |
else | |
-- go to the next page | |
s_forceTap = true | |
os.execute("xdotool mousemove 500 500 click 1") | |
end | |
end | |
end | |
end | |
end | |
end | |
--[[ | |
handle down. grab a time stamp to use to determine a home hold | |
]]-- | |
function handleHomeKeyDown() | |
log("home key down") | |
-- set state so we can catch press and hold onhome key | |
s_homeKeyDownState.screenShotTaken = false | |
s_homeKeyDownState.isDown = true | |
s_homeKeyDownState.timeStamp = os.time() | |
end | |
-- {{{ Key bindings | |
globalkeys = awful.util.table.join( | |
awful.key({ "Shift", }, "j", print_dbg_info), | |
awful.key({ "Shift", }, "f", dumpFocusInfo), | |
awful.key({ "Shift", }, "c", function() log("shift c down") end, chrome_raise), | |
awful.key({ "Shift", }, "x", function() log("shift x down") end, chrome_lower), | |
awful.key({ "Any", }, "Home", handleHomeKeyDown, handleHomeKeyUp), | |
awful.key({ }, "F1", nil, accelerometerPortraitUp), | |
awful.key({ }, "F2", nil, accelerometerPortraitDown), | |
awful.key({ }, "F3", nil, accelerometerLandscapeLeft), | |
awful.key({ }, "F4", nil, accelerometerLandscapeRight) | |
) | |
-- }}} | |
--[[ | |
Tap Handling code to follow | |
]]-- | |
local s_tapComboBeingHandled = false | |
--[[ | |
button 1 is screen tap | |
set c.signalHandled to true to block button from being | |
propogated to the client | |
]]-- | |
function handleClientButton1Press(c) | |
logTimeStamp("button 1 down") | |
if not c then | |
return | |
end | |
-- check to see if home is held down to put us into screen shot mode and | |
-- validate if we have already taken a screen shot on this hold | |
--[[ | |
if not s_homeKeyDownState.screenShotTaken and s_homeKeyDownState.isDown and os.difftime(os.time(), s_homeKeyDownState.timeStamp) > 1 then | |
llog.info("WindowManager", "tapHandledByWinMgr", "ID=Button1Down, reason=pendingScreenShot", "") | |
-- mark handled | |
c.signalHandled = true | |
s_tapComboBeingHandled = true | |
s_homeKeyDownState.screenShotTaken = true | |
-- take screen shot | |
os.execute ("screenshot &") | |
return | |
end | |
]]-- | |
-- eat taps when screen is paused | |
if liglIsPaused() then | |
llog.info("WindowManager", "tapHandledByWinMgr", "ID=Button1Down, reason=screenPaused", "") | |
s_tapComboBeingHandled = true | |
c.signalHandled = true | |
return | |
end | |
local c = c | |
local window = windowTableFindByClient(c) | |
if not window or not window.params then | |
return | |
end | |
logStrings({"client button 1 press", c.name}) | |
log("nofocus " .. tostring(c.nofocus)) | |
c.signalHandled = false | |
local focusedClient = client.focus | |
local focusedWindow = focusedClient and windowTableFindByClient(focusedClient) | |
if focusedClient and focusedClient.modal then | |
log("tap 1 while modal dialog has focus") | |
-- eat any and all taps/gestures not directed at the modal window or KB | |
if c ~= focusedClient and window.params.L ~= "KB" | |
and c.transient_for ~= focusedClient and focusedClient.transient_for ~= c then | |
llog.info("WindowManager", "tapHandledByWinMgr", "ID=Button1Down, reason=tapOffModal", "") | |
s_tapComboBeingHandled = true | |
c.signalHandled = true | |
else | |
setFocusedClient(c) | |
end | |
elseif focusedWindow and focusedWindow.params and focusedWindow.params.L == "D" | |
and window.params.N == "titleBar" then | |
log("tap on titleBar while non-modal dialog has focus") | |
s_tapComboBeingHandled = true | |
c.signalHandled = true | |
elseif c.nofocus then | |
log("non focusable window, do not eat the tap") | |
setControlClient(c) | |
elseif focusedClient == c then | |
llog.info("*** MBG", "no swipe", "focusedClient == c", "") | |
local inReader = focusedWindow.params.ID == "com.lab126.booklet.reader" | |
if not inReader or s_homeKeyDownState.isDown or s_forceTap then | |
llog.info("*** MBG", "no swipe", "focusedClient == c", "tap accepted") | |
log("window already has focus, do not eat the tap") | |
if s_forceTap then | |
s_blockHome = false -- we want to be able to use the home key immediately afterwards | |
s_forceTap = false | |
else | |
s_blockHome = true -- this stops the home key release event from happening (use when overriding tap blocking with the home key) | |
end | |
setControlClient(c) | |
else | |
-- mark handled | |
c.signalHandled = true | |
s_tapComboBeingHandled = true | |
llog.info("*** MBG", "no swipe", "focusedClient == c", "tap rejected") | |
end | |
else | |
-- check for current focus is on chrome and chrome is up | |
log("focusable window") | |
if focusedClient then | |
-- check to see if tap was off of chrome while | |
-- we are on chrome now | |
if (chrome_is_up() or keyboard_is_visible()) and | |
focusedWindow and chrome_is_chrome_window(focusedWindow) and | |
not chrome_is_chrome_window(window) then | |
llog.info("WindowManager", "tapHandledByWinMgr", "ID=Button1Down, reason=chromeDown", "tap will result in chrome being dismissed") | |
c.signalHandled = true | |
s_tapComboBeingHandled = true | |
end | |
end | |
setFocusedClient(c) | |
end | |
end | |
--[[ | |
button 1 is screen tap | |
set c.signalHandled to true to block button from being | |
propogated to the client | |
]]-- | |
function handleClientButton1Release(c) | |
if s_tapComboBeingHandled then | |
c.signalHandled = true | |
s_tapComboBeingHandled = false | |
end | |
end | |
--[[ | |
button 0 is a generic mapping to any button | |
set c.signalHandled to true to block button from being | |
propogated to the client | |
]]-- | |
function handleClientButton0Press(c) | |
log ("client button 0 press") | |
if s_tapComboBeingHandled then | |
llog.info("WindowManager", "tapHandledByWinMgr", "ID=Button0Down", "") | |
c.signalHandled = true | |
end | |
end | |
--[[ | |
button 0 is a generic mapping to any button | |
set c.signalHandled to true to block button from being | |
propogated to the client | |
]]-- | |
function handleClientButton0Release(c) | |
log ("client button 0 press release") | |
if s_tapComboBeingHandled then | |
llog.info("WindowManager", "tapHandledByWinMgr", "ID=Button0Up", "") | |
c.signalHandled = true | |
end | |
end | |
--[[ | |
End Tap Handling | |
]]-- | |
-- {{{ button bindings to add to every client | |
clientbuttons = awful.util.table.join( | |
awful.button({ }, 0, handleClientButton0Press, handleClientButton0Release), | |
awful.button({ }, 1, handleClientButton1Press, handleClientButton1Release) | |
) | |
-- }}} | |
-- Set keys | |
root.keys(globalkeys) | |
--[[ | |
awesome callback on a client when the title is changed | |
]]-- | |
function clientSignalNameChanged(c) | |
-- because we use the title as a set of key/value pairs | |
-- describing how to use this client, if the name changed | |
-- to remanage it | |
log("client name changed, new name %s", c.name) | |
updateClientName(c) | |
local window = windowTableFindByClient(c) | |
-- if a focused client is backgrounded | |
-- move the focus to the next client | |
if c == client.focus and window and | |
window.params.HIDE == "background" then | |
local nextFocusClient = awful.client.focus.history.get (1, 1) | |
if nextFocusClient then | |
log("client backgrounded, next focusable client is %s", nextFocusClient.name) | |
setFocusedClient(nextFocusClient) | |
end | |
end | |
if c == s_controlClient then | |
updateControlWindowName() | |
end | |
end | |
--[[ | |
awesome callback on a client when geometry changed | |
]]-- | |
function clientSignalGeometryChanged(c) | |
log("client geometry changed %s", c.name) | |
-- if this is a result of us resizing a client | |
-- there is nothing to do. However, if the client | |
-- was resized external to awesome (on the client side) | |
-- we need to remanage the client to ensure positioning | |
-- is still correct for the updated geometry | |
if (c == s_geometryChangingClient) then | |
log ("geometry change is internal") | |
-- fix trigger if present | |
liglHandleClientResize(c) | |
else | |
log ("geometry change is external") | |
updateClientGeometry(c) | |
-- look to see if geometry update was on the cotnrol window | |
if c == s_controlClient then | |
updateControlWindowGeometry() | |
end | |
end | |
end | |
-- {{{ Signals | |
--[[ | |
handle when a client changes which layer it is on | |
]]-- | |
function clientLayerChanged(c) | |
-- if control client is being lowered switch | |
-- control client to focused client | |
if c == s_controlClient and c.hiddenLayer then | |
s_controlClient = client.focus | |
end | |
-- hand to ligl to look for flashinging needs | |
liglHandleClientLayerChanged(c) | |
end | |
--[[ | |
awesome callback sent when a new client appears and can be managed. | |
There is also a "new" signal that fires but it seems the manage is the right | |
one to use | |
c : awesome client | |
]]-- | |
client.add_signal("manage", function (c, startup) | |
-- Log client information | |
log("*****manage signal fired ") | |
logStrings({"name : ", c.name}) | |
logStrings({"type : ", c.type}) | |
logStrings({"class: ", c.class}) | |
-- check buttons as is | |
local inButtonsTable = c:buttons() | |
print_table_contents("inButtonsTable", inButtonsTable, "") | |
--grab buttons | |
c:buttons(clientbuttons) | |
--look for property name changed | |
c:add_signal("property::name", clientSignalNameChanged) | |
c:add_signal("property::geometry", clientSignalGeometryChanged) | |
c:add_signal("property::hiddenLayer", clientLayerChanged) | |
addClient(c) | |
log("*****manage finished") | |
end) | |
--[[ | |
awesome callback sent when a client is unmapped or otherwise | |
no longer in scope of the winmgr | |
]]-- | |
client.add_signal("unmanage", function (c) | |
-- notify ligl as fast as possible | |
liglClientUnmanaged(c) | |
-- Log client information | |
log("*****unmanage signal fired") | |
logStrings({"name : ", c.name}) | |
logStrings({"type : ", c.type}) | |
logStrings({"class: ", c.class}) | |
removeClient(c) | |
-- if the focus was not resolved during removeClient, do it now | |
if not client.focus and awful.client.focus.history.get (1, 0) then | |
setFocusedClient(awful.client.focus.history.get (1, 0)) | |
end | |
if c == s_controlClient then | |
log("control client unmanaged - set it to focused client") | |
s_controlClient = client.focus | |
end | |
log("*****unmanage finished") | |
end) | |
-- We will manually add clients to focus history | |
client.remove_signal("focus", awful.client.focus.history.add) | |
--[[ | |
awesome callback sent when focus is set to new client | |
]]-- | |
client.add_signal("focus", function(c) | |
local expectedFocusedClient = awful.client.focus.history.get(1, 0) | |
if expectedFocusedClient and c ~= expectedFocusedClient then | |
-- There is an issue that we see speriodic focus | |
-- events from outside of the winmgr. This is to | |
-- catch that case. I need to further investigate | |
-- if we want to fix this onthe awesome c side instead | |
log("outside focus event rejected") | |
client.focus = expectedFocusedClient | |
return | |
end | |
logStrings({"focus changed to ", c.name}) | |
if s_tempHackToStopFocusAfterChromeRaise then | |
log("temp hack in place for home button chroming") | |
s_tempHackToStopFocusAfterChromeRaise = false | |
return | |
end | |
local window = windowTableFindByClient(c) | |
if not window or not window.params then | |
return | |
end | |
if c.name then | |
setControlClient(c) | |
-- if focus goes off of chrome while chrome is up then | |
-- dismiss chrome. the exception is titleBar or pillowAlert | |
-- or a dialog that marks itself as Chrome | |
if chrome_is_up() then | |
if not chrome_is_chrome_window(window) and | |
not (window.params.L == "D" and window.params.N == "pillowAlert") then | |
log("user tapped off of chrome hiding chrome") | |
chrome_lower() | |
end | |
end | |
updateActiveApplicationWindow(c) | |
if window.params.RKB then | |
logStrings ({"setting g_keyboardDialogClient to ", c.name}) | |
g_keyboardDialogClient = c | |
log("++++++++++++OPENING KB ON keyboard dialog take focus") | |
lipcH:set_string_property("com.lab126.keyboard", "open", ":" .. window.params.RKB .. ":256") | |
end | |
if application_is_application_window(window) or | |
window.params.L == "SS" then | |
setAppOrientation(window.params.O) | |
else | |
if g_activeApplicationWindow then | |
setAppOrientation(g_activeApplicationWindow.params.O) | |
end | |
end | |
end | |
end) | |
--[[ | |
awesome callback sent when a client loses focus | |
]]-- | |
client.add_signal("unfocus", function(c) | |
logStrings({"=====focus lost from ", c.name}) | |
-- if the removed dialog is the keyboard dialog | |
if g_keyboardDialogClient == c then | |
log ("g_keyboardDialogClient lost focus") | |
-- call KB to HIDE | |
log("++++++++++++CLOSING KB ON FOCUS LOST") | |
lipcH:set_string_property("com.lab126.keyboard", "close", ":256") | |
log ("clearing g_keyboardDialogClient") | |
g_keyboardDialogClient = nil | |
end | |
end) | |
g_screenOne:add_signal("rotate", function() | |
log("Screen rotated " .. g_screenOne.geometry.width .. " x " .. g_screenOne.geometry.height) | |
-- unlock the unpaused rect on titlebar so it can show again | |
liglLockUnpausedRect(false) | |
liglScreenRotated() | |
layoutLayers() | |
end) | |
-- }}} Signals | |
--[[ | |
-- {{{ Rules - Note that rules fire before the manage signal | |
awful.rules.rules = { | |
-- All clients will match this rule. | |
{ rule = { }, | |
callback = function() print("*****all rule fired*****") end }, | |
{ rule = { name = "pillowTopBar" }, | |
callback = function() print("*****pillowTopBar rule fired*****") end }, | |
} | |
--]] | |
-- }}} | |
--[[ | |
initializes layering logic, sets up callbacks etc. | |
]]-- | |
function initLayers() | |
log("++++++setting up layers") | |
local appLayer = findLayer("A") | |
appLayer.layoutFunc = ligl_layout(ew_layout(applicationLayer_layout)) | |
local chromeLayer = findLayer("C") | |
chromeLayer.layoutFunc = ligl_layout(chromeLayer_layout) | |
local dialogLayer = findLayer("D") | |
dialogLayer.layoutFunc = ligl_layout(ew_layout(dialogLayer_layout)) | |
local kbLayer = findLayer("KB") | |
kbLayer.layoutFunc = ligl_layout(keyboardLayer_layout) | |
local screenSaverLayer = findLayer("SS") | |
screenSaverLayer.layoutFunc = ligl_layout(screenSaverLayer_layout) | |
end | |
awesome.add_signal("onawesomeready", function() | |
liglInitialize(lipcH) | |
end) | |
-- handle errors so we can log stack trace | |
awesome.add_signal("debug::error", logErrorAndStackTrace) | |
--initialize all layers | |
initLayers() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment