Home of the Squeezebox™ & Transporter® network music players.
Results 1 to 10 of 55

Thread: JiveLite

Threaded View

  1. #29
    Senior Member
    Join Date
    Sep 2015
    Posts
    218

    attempted changes to AutoSkin applet

    Hi again,

    I have made my first attempted changes to the AutoSkin applet to try to make it respond to keyboard (ir-keytable) KEY_UP, KEY_DOWN, KEY_RIGHT and KEY_PLAY events.

    I have no coding experience, so apologies in advance if answers should be very obvious!

    My first problem is identifying a jive/ui/Framework function that returns a key name (similar to getIRCodes for arrow_up, arrow_down, arrow_right and play remote button presses).

    I tried getAction, as it looked like it should return Keycode for key press actions:

    Code:
    function getAction(self, event)
    	local eventType = event:getType()
    	local action = nil
    
    	if eventType == jive.ui.EVENT_KEY_PRESS then
    		action = self.inputToActionMap.keyActionMappings.press[event:getKeycode()]
    	elseif eventType == jive.ui.EVENT_GESTURE then
    		action = self.inputToActionMap.gestureActionMappings[event:getGesture()]
    	elseif eventType == jive.ui.EVENT_KEY_HOLD then
    		action = self.inputToActionMap.keyActionMappings.hold[event:getKeycode()]
    	elseif eventType == jive.ui.EVENT_CHAR_PRESS then
    		action = self.inputToActionMap.charActionMappings.press[string.char(event:getUnicode())]
    	elseif eventType == jive.ui.EVENT_IR_PRESS then
    		action = inputToActionMap.irActionMappings.press[self:getIRButtonName(event:getIRCode())]
    	elseif eventType == jive.ui.EVENT_IR_HOLD then
    		action = inputToActionMap.irActionMappings.hold[self:getIRButtonName(event:getIRCode())]
    	end
    
    	return action
    end
    but I was wrong as the log shows:
    tail -f /var/log/jivelite.log
    20210103 15:19:51.416 DEBUG jivelite.ui - Widget.lua:437 Creating widget action listener for action: (go_home) from source: [...pplets/ChooseMusicSource/ChooseMusicSourceApplet.lua]:767
    20210103 15:19:51.416 DEBUG jivelite.ui - Widget.lua:437 Creating widget action listener for action: (go) from source: [/opt/jivelite/share/jive/jive/ui/Slider.lua]:108
    20210103 15:19:51.416 DEBUG jivelite.ui - Widget.lua:437 Creating widget action listener for action: (play) from source: [/opt/jivelite/share/jive/jive/ui/Slider.lua]:109
    20210103 15:19:51.416 DEBUG jivelite.ui - Widget.lua:437 Creating widget action listener for action: (page_up) from source: [/opt/jivelite/share/jive/jive/ui/Textarea.lua]:129
    20210103 15:19:51.416 DEBUG jivelite.ui - Widget.lua:437 Creating widget action listener for action: (page_down) from source: [/opt/jivelite/share/jive/jive/ui/Textarea.lua]:130
    20210103 15:19:51.416 DEBUG jivelite.ui - Framework.lua:780 Translated action title_left_press to back
    20210103 15:19:51.417 DEBUG jivelite.ui - Framework.lua:780 Translated action title_right_press to go_now_playing

    Can anyone suggest where I should find the function that returns key press events?

    Here's the complete code for the first draft of the revised applet:



    Code:
    --[[
    =head1 NAME
    
    applets.AutoSkin.AutoSkinApplet - An applet to select different SqueezePlay skins
    
    =head1 DESCRIPTION
    
    This applet allows the SqueezePlay skin to be selected.
    
    =head1 FUNCTIONS
    
    Applet related methods are described in L<jive.Applet>. 
    AutoSkinApplet overrides the following methods:
    
    =cut
    --]]
    
    local ipairs, pairs = ipairs, pairs
    
    local oo              = require("loop.simple")
    local Applet          = require("jive.Applet")
    
    local Framework       = require("jive.ui.Framework")
    local Surface         = require("jive.ui.Surface")
    
    local jiveMain        = jiveMain
    local appletManager   = appletManager
    
    local debug           = require("jive.utils.debug")
    
    module(..., Framework.constants)
    oo.class(_M, Applet)
    
    --service method
    function getActiveSkinType(self)
    	return self.mode
    end
    
    function init(self, ...)
    
    	-- skins, could be configurable via settings
    	local touchSkin = "touch"
    	local remoteSkin = "remote"
    
    	--temp workaround, until it is resolved how to avoid self.mode being null on startup
    	--if not self.mode then
    	--	self.mode = nil
    	--end
    	
    	if not self.irBlacklist then
    		self.irBlacklist = {}
    
    		-- see jive.irMap_default for defined buttons
    		for x, button in ipairs({
    			"arrow_up",
    			"arrow_down",
    		--	"arrow_left",
    			"arrow_right",
    			"play",
    		--	"add",
    		--	"now_playing",
    		}) do
    			local irCodes = Framework:getIRCodes(button)
    			
    			for name, irCode in pairs(irCodes) do
    				self.irBlacklist[irCode] = button
    			end
    		end
    
    	end
    
            local eatIREvents = false
    
            if not self.keyBlacklist then
    		self.keyBlacklist = {}
    
    		-- see share/jive/jive/ui/Textinput.lua for defined keys
    		for x, key in ipairs({
    			"KEY_UP",
    			"KEY_DOWN",
    		--	"KEY_LEFT",
    			"KEY_RIGHT",
    			"KEY_PLAY",			
    		}) do
    			local keyCodes = Framework:getAction(key)
    			
    			for name, keyCode in pairs(keyCodes) do
    				self.keyBlacklist[keyCode] = key
    			end
    		end
    
    	end
    
            local eatKEYEvents = false
    	
    		
    	Framework:addListener(EVENT_IR_ALL,
    		function(event)
    			-- ignore initial keypress after switching from touch to IR control
    			if eatIREvents then
    
    				if event:getType() == EVENT_IR_UP then
    					eatIREvents = false
    				end
    				return EVENT_CONSUME
    
    			elseif self:changeSkin(remoteSkin) and self.irBlacklist[event:getIRCode()] ~= nil then
    
    				log:warn("ignore me - key " .. self.irBlacklist[event:getIRCode()] .. " is context sensitive")
    				eatIREvents = true
    				return EVENT_CONSUME
    
    			end
    
    			return EVENT_UNUSED
    		end,
    		-100)
    
    	Framework:addListener(EVENT_KEY_ALL,
    		function(event)
    			-- ignore initial keypress after switching from touch to KEY control
    			if eatKEYEvents then
    
    				if event:getType() == EVENT_KEY_UP then
    					eatKEYEvents = false
    				end
    				return EVENT_CONSUME
    
    			elseif self:changeSkin(remoteSkin) and self.keyBlacklist[event:getKeycode()] ~= nil then
    
    				log:warn("ignore me - key " .. self.keyBlacklist[event:getKeycode()] .. " is context sensitive")
    				eatKEYEvents = true
    				return EVENT_CONSUME
    
    			end
    
    			return EVENT_UNUSED
    		end,
    		-100)
    
    	Framework:addListener(EVENT_MOUSE_ALL,
    		function(event)
    
    			-- ignore event when switching from remote to touch: we don't know what we're touching
    			-- wake up if in screensaver mode - this is a non critical action
    			if self:changeSkin(touchSkin) and not appletManager:callService("isScreensaverActive") then
    				log:warn("ignore me - I don't know what I'm touching!")
    				return EVENT_CONSUME
    			end
    
    			return EVENT_UNUSED
    		end,
    		-100)
    
    	return self
    end
    
    
    
    function changeSkin(self, skinType)
    	if  self.mode == skinType then
    		return false
    	end
    
    	local skinName = appletManager:callService("getSelectedSkinNameForType", skinType)
    	if jiveMain:getSelectedSkin() == skinName then
    		self.mode = skinType -- needed for inital setting of mode at start.
    		log:debug("skin already selected, not switching: ", skinName)
    		return false
    	end
    
            log:info(self,":changeSkin ",skinName,":",skinType)
    	local img1 = _capture("foo")
    
    	self.mode = skinType
    	jiveMain:setSelectedSkin(skinName)
    
    	local img2 = _capture("bar")
    
    	Framework:_startTransition(self._transitionFadeIn(img1, img2))
    
    	return true
    end
    
    
    function _capture(name)
    	local sw, sh = Framework:getScreenSize()
    	local img = Surface:newRGB(sw, sh)
    
    	Framework:draw(img)
    
    	return img
    end
    
    
    function _transitionFadeIn(oldImage, newImage)
    	-- use a fast transition
    
    	local startT
    	local transitionDuration = 100
    	local remaining = transitionDuration
    	local sw, sh = Framework:getScreenSize()
    	local scale = (transitionDuration * transitionDuration * transitionDuration) / sw
    	local animationCount = 0
    
    	local scale = 255 / transitionDuration
    
    
    	return function(widget, surface)
    			if animationCount == 0 then
    				--getting start time on first loop avoids initial delay that can occur
    				startT = Framework:getTicks()
    			end
    			local x = remaining * scale
    
    			newImage:blit(surface, 0, 0)
    			oldImage:blitAlpha(surface, 0, 0, x)
    
    			local elapsed = Framework:getTicks() - startT
    			remaining = transitionDuration - elapsed
    
    			if remaining <= 0 then
    				Framework:_killTransition()
    			end
    			animationCount = animationCount + 1
    		end
    end
    
    
    --[[
    
    =head1 LICENSE
    
    Copyright 2010 Logitech. All Rights Reserved.
    
    This file is licensed under BSD. Please see the LICENSE file for details.
    
    =cut
    --]]
    I also tried consuming from event.lua directly like so:

    Code:
    --			local keyCodes = Framework:getAction(key)
    --			
    --			for name, keyCode in pairs(keyCodes) do
    --				self.keyBlacklist[keyCode] = key
    			local keyCode = Event:getKeycode(key)
    			
    			for name, keyCode do
    				self.keyBlacklist[keyCode] = key
    			end
    		end
    
    	end

    BR.
    Last edited by Learnincurve; 2021-01-03 at 09:21.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •