rewrite run_or_raise with awesome libs.

This commit is contained in:
2018-05-20 18:01:52 +08:00
parent 9132ee80a4
commit ce04270479
4 changed files with 52 additions and 149 deletions

View File

@@ -1,105 +0,0 @@
-- aweror.lua
-- Save this file as "aweror.lua" in awesome's system library directory "/usr/local/share/awesome/lib",
-- "/usr/share/awesome/lib", or your own config directory "~/.config/awesome/".
-- You will also need a "ror.lua" file (contains your key bindings) in your config directory.
-- Now you need to generate and add the keybindings in your ~/.config/awesome/rc.lua
-- In the rc.lua file there will be a "root.keys(globalkeys)" command that sets
-- your keys, you need to add the following lines just before that command:
--
-- local ror = require("aweror")
-- globalkeys = awful.util.table.join(globalkeys, ror.genkeys(modkey))
-- get our key bindings from separate ror.lua file
require("ror")
local awful= require("awful")
local client=client
local pairs=pairs
local table=table
local allt1=table5
local print=print
local USE_T = true
--local USE_T = false
local aweror = {}
function aweror.run_or_raise(cmd, properties)
local clients = client.get()
local focused = awful.client.next(0)
local findex = 0
local matched_clients = {}
local n = 0
for i, c in pairs(clients) do
--make an array of matched clients
if match(properties, c) then
n = n + 1
matched_clients[n] = c
if c == focused then
findex = n
end
end
end
if n > 0 then
local c = matched_clients[1]
-- if the focused window matched switch focus to next in list
if 0 < findex and findex < n then
c = matched_clients[findex+1]
end
local ctags = c:tags()
if #ctags == 0 then
-- ctags is empty, show client on current tag
local curtag = awful.tag.selected()
awful.client.movetotag(curtag, c)
else
-- Otherwise, pop to first tag client is visible on
awful.tag.viewonly(ctags[1])
end
-- And then focus the client
client.focus = c
c:raise()
return
end
awful.util.spawn(cmd)
end
-- Returns true if all pairs in table1 are present in table2
function match (table1, table2)
for k, v in pairs(table1) do
if table2[k] == nil or (table2[k] ~= v and not table2[k]:find(v)) then
return false
end
end
return true
end
function genfun(t3)
local cmd=t3[1]
local rule=t3[2]
local flag=t3[3]
local table1={}
s1="class"
if flag then
s1=flag
end
table1[s1]=rule
return function()
aweror.run_or_raise(cmd,table1)
end
end
function aweror.genkeys(mod1)
rorkeys = awful.util.table.join()
for i,v in pairs(allt1) do
modifier=""
if i:len() > 1 then
modifier=i:sub(1, i:find("-")-1)
i=i:sub(-1,-1)
end
rorkeys = awful.util.table.join(rorkeys,
awful.key({ mod1, modifier}, i, genfun(v)))
end
return rorkeys
end
return aweror

40
awesome/pravitekeys.lua Normal file
View File

@@ -0,0 +1,40 @@
local awful = require("awful");
local altkey = "Mod1"
local modkey = "Mod4"
function run_or_raise (cmd, rule)
local matcher = function (c)
return awful.rules.match(c, rule)
end
awful.client.run_or_raise(cmd, matcher)
end
pravitekeys = awful.util.table.join(
awful.key({ altkey, "Control" }, "f",
function ()
run_or_raise("firefox", {class = "Firefox"})
end),
awful.key({ altkey, "Control" }, "v",
function ()
run_or_raise("VirtualBox", {class = "VirtualBox"})
end),
awful.key({ altkey, "Control" }, "r",
function ()
run_or_raise("urxvtc", {class = "URxvt"})
end),
awful.key({ altkey, "Control" }, "e",
function ()
run_or_raise("emacs", {class = "Emacs"})
end),
awful.key({ altkey, "Shift" }, "e",
function ()
run_or_raise("pcmanfm", {class = "Pcmanfm"})
end)
)
return pravitekeys

View File

@@ -71,7 +71,7 @@ awful.util.terminal = terminal
-- ❶❷❸❹❺❻❼❽❾❿ ➊➋➌➍➎➏➐➑➒➓ -- ❶❷❸❹❺❻❼❽❾❿ ➊➋➌➍➎➏➐➑➒➓
awful.util.tagnames = { "➊ term", "➋ web", "➌ doc", "➍ media", "➎ VirtualBox", "➏ others" } awful.util.tagnames = { "➊ term", "➋ web", "➌ doc", "➍ media", "➎ VirtualBox", "➏ others" }
awful.layout.layouts = { awful.layout.layouts = {
awful.layout.suit.tile, awful.layout.suit.fair.horizontal,
awful.layout.suit.floating, awful.layout.suit.floating,
awful.layout.suit.tile.bottom, awful.layout.suit.tile.bottom,
awful.layout.suit.fair, awful.layout.suit.fair,
@@ -424,7 +424,13 @@ globalkeys = awful.util.table.join(
-- User programs -- User programs
-- awful.key({ modkey }, "e", function () awful.spawn(gui_editor) end), -- awful.key({ modkey }, "e", function () awful.spawn(gui_editor) end),
awful.key({ modkey }, "e", function () awful.spawn("pcmanfm") end), awful.key({ modkey }, "e", function () awful.spawn("pcmanfm") end),
awful.key({ modkey }, "q", function () awful.spawn(browser) end), -- awful.key({ modkey }, "q", function () awful.spawn(browser) end),
awful.key({ modkey }, "q", function ()
local matcher = function (c)
return awful.rules.match(c, {class = "Firefox"})
end
awful.client.run_or_raise("firefox", matcher)
end),
-- Default -- Default
--[[ Menubar --[[ Menubar
@@ -542,11 +548,10 @@ clientbuttons = awful.util.table.join(
awful.button({ modkey }, 1, awful.mouse.client.move), awful.button({ modkey }, 1, awful.mouse.client.move),
awful.button({ modkey }, 3, awful.mouse.client.resize)) awful.button({ modkey }, 3, awful.mouse.client.resize))
-- load the 'run or raise' function local pravitekeys = require("pravitekeys")
local ror = require("aweror")
-- generate and add the 'run or raise' key bindings to the globalkeys table -- add the pravite key bindings to the globalkeys table
globalkeys = awful.util.table.join(globalkeys, ror.genkeys(altkey)) globalkeys = awful.util.table.join(globalkeys, pravitekeys)
-- Set keys -- Set keys
root.keys(globalkeys) root.keys(globalkeys)
@@ -571,7 +576,7 @@ awful.rules.rules = {
-- Titlebars -- Titlebars
{ rule_any = { type = { "dialog", "normal" } }, { rule_any = { type = { "dialog", "normal" } },
properties = { titlebars_enabled = true } }, properties = { titlebars_enabled = false } },
-- Set Firefox to always map on the second tag on screen 1. -- Set Firefox to always map on the second tag on screen 1.
{ rule = { class = "Firefox" }, { rule = { class = "Firefox" },

View File

@@ -1,37 +0,0 @@
-- ror.lua
-- This is the file goes in your ~/.config/awesome/ directory
-- It contains your table of 'run or raise' key bindings for aweror.lua
-- Table entry format: ["key"]={"function", "match string", "optional attribute to match"}
-- The "key" can include "Control-", "Shift-", and "Mod1-" modifiers (eg "Control-z")
-- The "key" will be bound as "modkey + key". (eg from above would end up as modkey+Control+z)
-- The "function" is what gets run if no matching client windows are found.
-- Usual attributes are "class","instance", or "name". If no attribute is given it defaults to "class".
-- The "match string" will match substrings. So "Firefox" will match "blah Firefox blah"
-- Use xprop to get this info from a window. WM_CLASS(STRING) gives you "instance", "class".
-- WM_NAME(STRING) gives you the name of the selected window (usually something like the web page title
-- for browsers, or the file name for emacs).
--[[
table5={
["Control-z"]={"google-chrome --app=http://www.rdio.com","www.rdio.com", "instance"},
["e"]={"emacsclient -a emacs -n -c","Emacs"},
["w"]={"firefox","Firefox"},
["v"]={"firefox -new-window 'http://www.evernote.com/Home.action?login=true#v=l&so=mn'","Evernote", "name"},
["g"]={"firefox -new-window 'http://mail.google.com/mail/'","Gmail","name"},
["x"]={"xterm","xterm", "instance"},
["f"]={"xterm -name mcTerm -e mc -d","mcTerm", "instance"},
["Shift-s"]={"xterm -name rootTerm -cr red -title rootTerm -e su","rootTerm", "instance"},
["t"]={"xterm -name htopTerm -e htop","htopTerm","instance"},
["b"]={"xterm -name rtorrentTerm -e rtorrent","rtorrentTerm","instance"},
["z"]={"xterm -name mocpTerm -e mocp","mocpTerm", "instance"}
}
--]]
-- ror.lua
table5={
["Control-f"]={"firefox","Firefox"},
["Control-v"]={"VirtualBox","VirtualBox"},
-- ["v"]={"gvim", "Gvim"},
["Control-r"]={"urxvtc","URxvt"},
["Control-e"]={"emacs", "Emacs"},
["Shift-e"]={"pcmanfm", "Pcmanfm"}
}