How to disable player from entering fullscreen window in love2d.

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
Falkyraizu
Prole
Posts: 10
Joined: Sun Mar 22, 2020 9:30 pm

How to disable player from entering fullscreen window in love2d.

Post by Falkyraizu »

When making a project I set the windoe dimensions o 800x400, and resizable to false, however this can easily be countered when the user enters fullscreen. Is there any way to disable the user from pressing the fullscreen icon, hense disabling them from entering fullscreen entirely?

-Sincerely, Falkyraizu
MrFariator
Party member
Posts: 512
Joined: Wed Oct 05, 2016 11:53 am

Re: How to disable player from entering fullscreen window in love2d.

Post by MrFariator »

When you call love.window.setMode, passing in a table that contains "resizable = false" should work.
Example:
Image

If that still somehow doesn't work, then I believe you have to share some code as to how you're setting the window flags; mentioning your OS probably wouldn't hurt, either.
Falkyraizu
Prole
Posts: 10
Joined: Sun Mar 22, 2020 9:30 pm

Re: How to disable player from entering fullscreen window in love2d.

Post by Falkyraizu »

MrFariator wrote: Fri Mar 27, 2020 11:24 am When you call love.window.setMode, passing in a table that contains "resizable = false" should work.
Example:
Image

If that still somehow doesn't work, then I believe you have to share some code as to how you're setting the window flags; mentioning your OS probably wouldn't hurt, either.
Your wrong. `resizable = false` makes the user unable to resize the window. The fullscreen button still works. I want to disable the user from entering fullscreen entirely. This is not going to help you, but if you want the code, here it is:

Code: Select all

WINDOW_WIDTH = 800
WINDOW_HEIGHT = 400
running = true
function love.load()
	love.graphics.setDefaultFilter('nearest', 'nearest')
	rFont = love.graphics.newFont('font.ttf', 16)
	love.window.setMode(WINDOW_WIDTH, WINDOW_HEIGHT, {
		fullscreen = false,
		resizable = false,
		vsync = true
	})
	stateMSG = 'Press [Space] to start the game'
	rColor, gColor, bColor = math.random(), math.random(), math.random()
	math.randomseed(os.time())
	ballX = WINDOW_WIDTH / 2 - 2
	ballY = WINDOW_HEIGHT / 2 - 2
	ballDX = math.random(2) == 1 and 100 or -100
	ballDY = math.random(-50,50)
	player1Y = WINDOW_HEIGHT / 2 - 40
	player2Y = WINDOW_HEIGHT / 2 - 40
	speed = 200
	gameState = 'waiting'
end

function love.update(dt)
	if love.keyboard.isDown('w') then
		player1Y = math.max(0, player1Y - speed * dt)
	elseif love.keyboard.isDown('s') then
		player1Y = math.min(WINDOW_HEIGHT - 80, player1Y + speed * dt)
	end
	if love.keyboard.isDown('up') then
		player2Y = math.max(0, player2Y - speed * dt)
	elseif love.keyboard.isDown('down') then
		player2Y = math.min(WINDOW_HEIGHT - 80, player2Y + speed * dt)
	end
	
	if gameState == 'playing' then
		ballX = ballX + ballDX * dt
		ballY = ballY + ballDX * dt
	end
end

function love.draw()
	love.graphics.setFont(rFont)
	love.graphics.setColor(1,1,1)
	love.graphics.clear(131/255, 111/255, 255/255)
	
	love.graphics.printf(stateMSG, 0, 20, WINDOW_WIDTH, 'center')
	
	love.graphics.rectangle('fill', 0, player1Y, 20, 80)
	love.graphics.rectangle('fill', WINDOW_WIDTH - 20, player2Y, 20, 80)
	love.graphics.setColor(rColor, gColor, bColor)
	
	love.graphics.rectangle('fill', ballX, ballY, 8, 8)
end

function love.keypressed(key)
	if key == 'escape' then
		love.event.quit()
	end
	if key == 'space' then
		if gameState == 'waiting' then
			gameState = 'playing'
			stateMSG = "Game in Progress. Press 'r' To Replay"
		end
	elseif key == 'r' then
		gameState = "waiting"
		ballX = WINDOW_WIDTH / 2 - 2
		ballY = WINDOW_HEIGHT / 2 - 2
		ballDX = math.random(2) == 1 and 100 or -100
		ballDY = math.random(-50,50)		
		stateMSG = "Round Reset! Press [Space] To Begin A New Round."
	    rColor, gColor, bColor = math.random(), math.random(), math.random()
	end
User avatar
slime
Solid Snayke
Posts: 3132
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: How to disable player from entering fullscreen window in love2d.

Post by slime »

With your code, the fullscreen button is completely disabled for me (macOS 10.15 - but it's been like this since around when we first implemented macOS Fullscreen-Spaces support in SDL in 2013-ish). SDL is supposed to disable it when window resizing is disabled on macOS, so the behaviour matches my expectations.

If you're using a different OS, the OS itself might be bypassing what the window requests. What sort of system are you using?

Here's a screenshot demonstrating that it's disabled:
Attachments
Screen Shot 2020-03-27 at 8.02.35 PM.png
Screen Shot 2020-03-27 at 8.02.35 PM.png (300.51 KiB) Viewed 4862 times
Falkyraizu
Prole
Posts: 10
Joined: Sun Mar 22, 2020 9:30 pm

Re: How to disable player from entering fullscreen window in love2d.

Post by Falkyraizu »

slime wrote: Fri Mar 27, 2020 11:04 pm With your code, the fullscreen button is completely disabled for me (macOS 10.15 - but it's been like this since around when we first implemented macOS Fullscreen-Spaces support in SDL in 2013-ish). SDL is supposed to disable it when window resizing is disabled on macOS, so the behaviour matches my expectations.

If you're using a different OS, the OS itself might be bypassing what the window requests. What sort of system are you using?

Here's a screenshot demonstrating that it's disabled:
I am on a chromebook. Linux is my operating system.
Edit; Since it is suppodesly an operating system problem, does that mean there is a way to tell the system to disable it? Is there any function that allows me to disable fullscreen since the resizable method isn;t working. Overall I wan't to ensure that users are not able to go into fullscreen when they view my project.
User avatar
pgimeno
Party member
Posts: 3550
Joined: Sun Oct 18, 2015 2:58 pm

Re: How to disable player from entering fullscreen window in love2d.

Post by pgimeno »

It's more of a window manager problem, but some OSes come with just one.

If your window manager doesn't honour the resize flag, that's a problem that needs to be fixed by the window manager authors.

WindowMaker is the one I use, and while it doesn't disable the maximize options (assuming that's what you mean by fullscreen), the window doesn't become larger when I select them anyway.

If it's so important for you, you can just draw to a canvas of the desired target size and draw that canvas centred on the screen. Or you can use the scissor to clip the drawing area. If some user manages to work around the resizing limitation, they will just see the same area they see when the window is normal.
MrFariator
Party member
Posts: 512
Joined: Wed Oct 05, 2016 11:53 am

Re: How to disable player from entering fullscreen window in love2d.

Post by MrFariator »

Technically you could also query the window's current resolution with love.window.getMode(), and check if it's fullscreened, maximized, or something else. If it's something you don't want it to be, then just set the mode to the desired resolution. This, however, is a very janky solution, and probably only worth doing if you're really bent on keeping user's window, well, windowed.

Because this seems to be an window manager specific issue, however, you should be fine with pgimeno's advice. A good chunk of end users probably won't notice the issue at all, considering Windows and OSX (and iirc, stock Ubuntu) respect the resize flag just fine in my experience.
Post Reply

Who is online

Users browsing this forum: No registered users and 217 guests