<commit_before><commit_msg>#240 * Initial addition of the `os.touchbar` plugin.<commit_after>-- Includes
local touchbar 									= require("hs._asm.touchbar")
local settings									= require("hs.settings")
local eventtap									= require("hs.eventtap")

-- The Module
local mod = {}

function mod.isSupported()
	return touchbar.supported()
end

function mod.getLastLocation()
	settings.get("fcpxHacks.lastTouchBarLocation")
end

function mod.setLastLocation(value)
	settings.set("fcpxHacks.lastTouchBarLocation", value)
end

function mod.init()
	--------------------------------------------------------------------------------
	-- New Touch Bar:
	--------------------------------------------------------------------------------
	mod.touchBarWindow = touchbar.new()

	--------------------------------------------------------------------------------
	-- Touch Bar Watcher:
	--------------------------------------------------------------------------------
	mod.touchBarWindow:setCallback(touchbarWatcher)

	--------------------------------------------------------------------------------
	-- Get last Touch Bar Location from Settings:
	--------------------------------------------------------------------------------
	local lastTouchBarLocation = mod.getLastLocation()
	if lastTouchBarLocation ~= nil then	mod.touchBarWindow:topLeft(lastTouchBarLocation) end

	--------------------------------------------------------------------------------
	-- Draggable Touch Bar:
	--------------------------------------------------------------------------------
	local events = eventtap.event.types
	touchbarKeyboardWatcher = eventtap.new({events.flagsChanged, events.keyDown, events.leftMouseDown}, function(ev)
		if mod.mouseInsideTouchbar then
			if ev:getType() == events.flagsChanged and ev:getRawEventData().CGEventData.flags == 524576 then
				mod.touchBarWindow:backgroundColor{ red = 1 }
							  	:movable(true)
							  	:acceptsMouseEvents(false)
			elseif ev:getType() ~= events.leftMouseDown then
				mod.touchBarWindow:backgroundColor{ white = 0 }
							  :movable(false)
							  :acceptsMouseEvents(true)
				mod.setLastLocation(mod.touchBarWindow:topLeft())
			end
		end
		return false
	end):start()
end

-- The Plugin
local plugin = {}

function plugin.init(deps)
	return mod
end

return plugin
{'fraction_non_alphanumeric': 0.35391304347826086, 'fraction_numerical': 0.004782608695652174, 'mean_word_length': 1.3894080996884735, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6426273', 'n_tokens_mistral': 611, 'n_tokens_neox': 531, 'n_words': 115}