Skip to content

Commit

Permalink
add cursor centering on focus
Browse files Browse the repository at this point in the history
  • Loading branch information
cpdean committed Sep 17, 2014
1 parent 8905daf commit 9e76269
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .mjolnir/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ local hotkey = require "mjolnir.hotkey"
local window = require "mjolnir.window"
local fnutils = require "mjolnir.fnutils"
local alert = require "mjolnir.alert"
local cursor = require "mjolnir.jstevenson.cursor"

local intense = {"ctrl", "shift", "alt"}
local usual = {"ctrl", "shift"}
Expand All @@ -13,6 +14,13 @@ hotkey.bind(intense, "p", function()
alert.show(important, 1)
end)


local center_cursor_on = function(win_obj)
local f = win_obj:frame()
cursor.warptopoint(f.x + (f.w / 2), f.y + (f.h / 2))
end

-- create a new switcher, assumes "intense" and "usual" modifiers
local create_mjm_switcher = function(key_register)
local this_id = 0 -- store window id
local this_previous = 0 -- store window before switching focus
Expand All @@ -29,14 +37,17 @@ local create_mjm_switcher = function(key_register)
local current = window.focusedwindow():id()
if current == this_id then
window.windowforid(this_previous):focus()
center_cursor_on(window.windowforid(this_previous))
else
this_previous = current
window.windowforid(this_id):focus()
center_cursor_on(window.windowforid(this_id))
end
end)

end

-- add some bindings
create_mjm_switcher("i")
create_mjm_switcher("u")
create_mjm_switcher("o")

0 comments on commit 9e76269

Please sign in to comment.