I am trying to define a custom lua configuration for the nvim-qt GUI. In order to do so, I would first like to toggle fullscreen on and off, but I encounter some pretty weird behavior.
vim.g.nvim_qt = {
fullscreen = false,
fontsize = 14,
font_name = 'Iosevka\\ NF:h'
}
local toggle_fullscreen = function ()
vim.g.nvim_qt.fullscreen = not vim.g.nvim_qt.fullscreen
if vim.g.nvim_qt.fullscreen then
return '1'
else
return '0'
end
end
--vim.cmd('call GuiWindowFullScreen(' .. toggle_fullscreen() ..')')
vim.keymap.set('n', '<F11>', ':call GuiWindowFullScreen(' .. toggle_fullscreen() ..')<CR>')
What I would expect, is the value of fullscreen to be toggled on each function call. It however always remains false. Can anyone explain why this happens?
I'm not 100% familiar with the Neovim-qt framework, but your toggle_fullscreen() function does seems to work fine. When running this locally, I get the toggling behavior.
Could you provide some more information how the keymap exactly works? My guess is that the set() function simple runs the toggle_fullscreen once and saves it in the keymap as ":call GuiWindowFullScreen(0)", which leads you to always calling the function with a false value.
Related
I have a Lua function where I build a table of value and attempt to add it to a global table with a named key.
The key name is pulled from the function arguments. Basically, it's a filename, and I'm pairing it up with data about the file.
Unfortunately, the global table always comes back nil. Here's my code: (let me know if you need to see more)
(Commented parts are other attempts, although many attempts have been deleted already)
Animator = Class{}
function Animator:init(atlasfile, stringatlasfriendlyname, totalanimationstates, numberofframesperstate, booleanstatictilesize)
-- Define the Animator's operation mode. Either static tile size or variable.
if booleanstatictilesize ~= false then
self.isTileSizeStatic = true
else
self.isTileSizeStatic = false
end
-- Define the total animation states (walking left, walking right, up down, etc.)
-- And then the total frames per state.
self.numAnimationStates = totalanimationstates or 1
self.numAnimationFrames = numberofframesperstate or 2
-- Assign the actual atlas file and give it a programmer-friendly name.
self.atlasname = stringatlasfriendlyname or removeFileExtension(atlasfile, 'animation')
generateAnimationQuads(atlasfile, self.atlasname, self.numAnimationStates, self.numAnimationFrames)
end
function generateAnimationQuads(atlasfile, atlasfriendlyname, states, frames)
spriteWidthDivider = atlasfile:getWidth() / frames
spriteHeightDivider = atlasfile:getHeight() / states
animationQuadArray = generateQuads(atlasfile, spriteWidthDivider, spriteHeightDivider)
animationSetValues = {atlasarray = animationQuadArray, width = spriteWidthDivider, height = spriteHeightDivider}
--gAnimationSets[#gAnimationSets+1] = atlasfriendlyname
gAnimationSets[atlasfriendlyname] = animationSetValues
--table.insert(gAnimationSets, atlasfriendlyname)
end
Note: when using print(atlasfriendlyname) and print(animationSetValues), neither are empty or nil. They both contain values.
For some reason, the line(s) that assign the key pair to gAnimationSets does not work.
gAnimationSets is defined a single time at the top of the program in main.lua, using
gAnimationSets = {}
Animator class is called during the init() function of a character class called Bug. And the Bug class is initialized in the init() function of StartState, which extends from BaseState, which simply defines dummy init(), enter(), update() etc. functions.
StartState is invoked in main.lua using the StateMachine class, where it is passed into StateMachine as a value of a global table declared in main.lua.
gAnimationSets is declared after the table of states and before invoking the state.
This is using the Love2D engine.
Sorry that I came here for help, I've been picking away at this for hours.
Edit: more testing.
Trying to print the animationQuadArray at the index gTextures['buganimation'] always returns nil. Huh?
Here's gTextures in Main.lua
gTextures = {
['background'] = love.graphics.newImage('graphics/background.png'),
['main'] = love.graphics.newImage('graphics/breakout.png'),
['arrows'] = love.graphics.newImage('graphics/arrows.png'),
['hearts'] = love.graphics.newImage('graphics/hearts.png'),
['particle'] = love.graphics.newImage('graphics/particle.png'),
['buganimation'] = love.graphics.newImage('graphics/buganimation.png')
}
Attempting to return gTextures['buganimation'] returns a file value as normal. It's not empty.
My brain is so fried right now I can't even remember why I came to edit this. I can't remember.
Global table in Main.lua, all other functions can't access it.
print(gTextures['buganimation']) works inside the function in question. So gTextures is absolutely accessible.
Table isn't empty. AnimationSetValues is not empty.
I'm adding second answer because both are correct in context.
I ended up switching IDE's to VS Code and now the original one works.
I was originally using Eclipse LDT with a Love2D interpreter and in that environment, my original answer is correct, but in VS Code, the original is also correct.
So Dimitry was right, they are equivalent, but something about my actual Eclipse setup was not allowing that syntax to work.
I switched to VS Code after I had another strange syntax problem with the interpreter where goto syntax was not recognized and gave a persistent error. The interpreter thought goto was the name of a variable.
So I switched, and now both things are fixed. I guess I just won't use LDT for now.
Solution: Lua syntax. Brain Fry Syndrome
I wrote:
animationSetValues = {atlasarray = animationQuadArray, width = spriteWidthDivider, height = spriteHeightDivider}
Should be:
animationSetValues = {['atlasfile']=atlasfile, ['atlasarray']=animationQuadArray, ['width']=spriteWidthDivider, ['height']=spriteHeightDivider}
Edit: I'm fully aware of how to use answers. This was posted here to reserve my spot for an answer so I could edit it later when I returned back home, which is exactly what I'm doing right now. I'll keep the old post for archival purposes.
Original:
I solved it. I apologize for not posting the solution right now. My brain is melted into gravy.
I will post it tomorrow. Just wanted to "answer" saying no need to help. Solved it.
Solution is basically, "oh it's just one of those Lua things". Wonderful. I'm having so much fun with this language - you can tell by my blank expression.
From the language without line endings or brackets, but forced print parentheses... ugh. I'm going back to C# when this class is done.
[My code is :]
local function MWin()
game.StarterGui.ScreenGui1.DemonWin.Visible = true
if game.Workspace.Mages_Boss.Humanoid.Died:connect(function()
print("good")
end
[My noob is named : Mages_Boss
And my screen gui is named : DemonWin
I dont know what to put for "print("good")".]
First, modifying the starter GUI does nothing. You need to change the one player or all players with a for loop. In my answer, I’ll use the former with a player named ROBLOX. If you want to start with it invisible, you need game.Players.ROBLOX.PlayerGui.ScreenGui1.DemonWin.Visible = false. To make it visible on the death event, use game.Players.ROBLOX.PlayerGui.ScreenGui1.DemonWin.Visible = true.
Try using
DemonWin.Enabled=true;
or
DemonWin.Enabled=false;
to toggle whether it is active or not. I suppose in the died function, use the latter.
I'm going to assume you're not firing the function so you can get rid of that. You're also going to remove the .Died since it fires even when it's not dead. So your best bet would be to do also add a debounce- kind of function to your script. Here's the modified version:
game.StarterGui.ScreenGui1.DemonWin.Visible = false
if game.Workspace.Mages_Boss.Humanoid.Health == 0 then
game.StarterGui.ScreenGui1.DemonWin.Visible = true
else
game.StarterGui.ScreenGui1.DemonWin.Visible = false
end
Also, you would have to put the GUI in the StarterGui (located in game.Players.LocalPlayer.StarterGui) in order to not publicly malfunction this script.
In awesome 4.0, is there a way to only display the titlebar on floating windows?
Looking at the docs, there doesn't seem to be an option out of the box.
To specify; I'm looking for a solution that work when I dynamically switch windows between tiling and floating.
A bit late, but I wanted to do this too and I got it mostly working. It doesn't cover all the cases when you'd expect a client to show or hide its titlebar, but it's close enough for my use case.
It's rather simple, first you need to disable titlebars for every client, so add titlebars_enabled = false in the properties of the default rule matching all clients.
Then, when a client becomes floating you need to toggle on his titlebar, and toggle it off when it stops floating.
I wrote this little helper function to make the code clearer. It's rather simple, if s is true then show the bar, hide it otherwise. But there's a catch, in our case the windows never had a titlebar so it isn't created yet. We send the signal to have one built for us if the current one is empty.
-- Toggle titlebar on or off depending on s. Creates titlebar if it doesn't exist
local function setTitlebar(client, s)
if s then
if client.titlebar == nil then
client:emit_signal("request::titlebars", "rules", {})
end
awful.titlebar.show(client)
else
awful.titlebar.hide(client)
end
end
Now we can hook the property change:
--Toggle titlebar on floating status change
client.connect_signal("property::floating", function(c)
setTitlebar(c, c.floating)
end)
But that only applies to clients that changes states after being created. We need a hook for new clients that are born floating or in a floating tag:
-- Hook called when a client spawns
client.connect_signal("manage", function(c)
setTitlebar(c, c.floating or c.first_tag.layout == awful.layout.suit.floating)
end)
And finally, if the current layout is floating, clients don't have the floating property set, so we need to add a hook for layout changes to add the tittlebars on clients inside.
-- Show titlebars on tags with the floating layout
tag.connect_signal("property::layout", function(t)
-- New to Lua ?
-- pairs iterates on the table and return a key value pair
-- I don't need the key here, so I put _ to ignore it
for _, c in pairs(t:clients()) do
if t.layout == awful.layout.suit.floating then
setTitlebar(c, true)
else
setTitlebar(c, false)
end
end
end)
I didn't want to spend to much time on this so it doesn't cover cases where a client gets tagged in a floating layout, or when a client is tagged multiple times and one of those tag is floating.
Change
{ rule_any = {type = { "normal", "dialog" }
}, properties = { titlebars_enabled = true }
},
to
{ rule_any = {type = { "dialog" }
}, properties = { titlebars_enabled = true }
},
Niverton's solution works very well for simply switching from tiling to floating modes; however, floating windows will lose their titlebar when maximized and then unmaximized. To fix this, a better solution would be to replace
client.connect_signal("property::floating", function(c)
setTitlebar(c, c.floating)
end)
with
client.connect_signal("property::floating", function(c)
setTitlebar(c, c.floating or c.first_tag and c.first_tag.layout.name == "floating")
end)
This should fix the issue so that windows can be properly maximized without having to switch to tiling mode and back to get the titlebars again.
I found this general idea on a reddit post about the subject, provided by u/Ham5andw1ch. I have just simplified the code using Niverton's proposed function and some short-circuit logic.
I'm changing something in an Addon for World of Warcraft which are written in Lua.
There is a simple boolean variable which determines if some "all" frames are shown or only specific one.
So when = true then it will only show specific frames
when = false it will show all frames
I want to make a modifier with the shift key to show all frames when the shiftkey is pressed and hide them again when shift is realeased.
if IsShiftKeyDown() then
cfg.aura.onlyShowPlayer = false
else
cfg.aura.onlyShowPlayer = true
end
This is my very simple solution for it which works. The problem here is though it only works on starting of the script. You see in WoW everytime the interface gets loaded it will run the script if not told otherwise. That is not very efficent because I would send my user into a loadingscreen.
OnUpdate should fix my problem here which will run this specific code everytime a frame gets rendered which is pretty handy and is what I want to accomplish.
So this is what I made
local function onUpdate(self,elapsed)
if IsShiftKeyDown() then
cfg.aura.onlyShowPlayer = false
else
cfg.aura.onlyShowPlayer = true
end
end
local shiftdebuffs = CreateFrame("frame")
shiftdebuffs:SetScript("OnUpdate", onUpdate)
My problem is now that it doesn't work. I new to the onUpdate stuff and only copy pasted it from another addon I did which worked fine.
Right it goes straight to = false, which is only happening I think because it is the default.
thanks for the help
Right it goes straight to = false, which is only happening I think because it is the default.
No, there is no "default" branch in the if statement. For the control to get to the then branch the condition has to be evaluated to true. You need to check the logic, but if the script executed cfg.aura.onlyShowPlayer = false, it means that IsShiftKeyDown() was evaluated as true.
I am trying to get a trigger that will show with the sunfire debuff has less time then my nature's grace buff. the lua calls seem to be pulling the correct number, but it is constantly returning true?
function ()
_,_,_,_,_,_,sundur= UnitDebuff("target","Sunfire","player");
_,_,_,_,_,_,NGDur= UnitAura("player","Nature's Grace");
if sundur and NGDur then
if sundur<NGDur+2 then
return true
else
return false
end
end
end
The issue i found was that the ad don was allowing the declared variables to be saved globally which was causing it not to be updated properly even as i changed them. I also had to change one part of code, removing the "" around player only on the uniteDebuff "caster" filter.
local _,_,_,_,_,_,sundur= UnitDebuff("target","Sunfire",player);