tcod-rs icon indicating copy to clipboard operation
tcod-rs copied to clipboard

Switching to fullscreen doesn't work on Ubuntu

Open tomassedovic opened this issue 4 years ago • 10 comments

Originally reported by u/PollenX on Reddit:

https://www.reddit.com/r/rust_gamedev/comments/e9v0x0/tcod_fullscreen_toggle_not_working/

Calling set_fullscreen(true) after the root console has been initialised does not have any effect. This seems to have something to do with the size call in the root console initialiser. When they remove it, they are able to toggle fullscreen.

Here is the root console initialisation code they use:

let mut root = Root::initializer().font("terminal16x16_gs_ro.png", FontLayout::AsciiInRow)
.font_type(FontType::Greyscale)
.size(SCREEN_WIDTH, SCREEN_HEIGHT)
.title("SssBall")
.init();

tcod-rs version: v0.15.0 OS: Ubuntu Linux 19.04

tomassedovic avatar Dec 15 '19 21:12 tomassedovic

For what it's worth, I've been unable to reproduce this on my own Linux (Fedora 30) setup with the SDL2-2.0.10-1.fc30.x86_64 and SDL2-devel-2.0.10-1.fc30.x86_64 packages.

Tried the following code (adapted form the keyboard example) on both tcod master and v.0.15.0:

extern crate tcod;

use tcod::{Console, RootConsole, BackgroundFlag};
use tcod::input::Key;
use tcod::input::KeyCode::{Up, Down, Left, Right, Escape, Enter};

fn main() {
    let mut con = RootConsole::initializer()
        .size(80, 50)
        .title("libtcod Rust tutorial")
        .init();

    let mut x = 40;
    let mut y = 25;
    while !con.window_closed() {
        con.clear();
        con.put_char(x, y, '@', BackgroundFlag::Set);
        con.flush();
        let keypress = con.wait_for_keypress(true);
        if keypress.pressed {
            match keypress {
                Key { code: Enter, alt: true, .. } => {
                    println!("pressed Alt+Enter");
                    let fullscreen = con.is_fullscreen();
                    con.set_fullscreen(!fullscreen);
                }
                Key { code: Escape, .. } => break,
                Key { code: Up, .. } => y -= 1,
                Key { code: Down, .. } => y += 1,
                Key { code: Left, .. } => x -= 1,
                Key { code: Right, .. } => x += 1,
                _ => {}
            }
        }
    }
}

Pressing alt+enter toggles the fullscreen off and on just like expected.

tomassedovic avatar Dec 15 '19 21:12 tomassedovic

Note, I'm mostly posting this here in hopes that someone else might be willing&able to investigate. I will not be able to do so for quite some time, sorry! :-(

tomassedovic avatar Dec 15 '19 21:12 tomassedovic

Just tried it on Windows and it works. The only thing is that it changes the resolution of the screen as well so that might cause a problem for you

L3nn0x avatar Dec 16 '19 11:12 L3nn0x

I'm the one with the issue. However it looks like user error because the test code works as expected.

Here's the code repository if anyone is curious to help me spot what I'm doing wrong.

https://github.com/Jacktwist/sssball

Jacktwist avatar Dec 18 '19 23:12 Jacktwist

Here's the code I'm using:

let mut root = Root::initializer() .font("terminal16x16_gs_ro.png", FontLayout::AsciiInRow) .font_type(FontType::Greyscale) .size(SCREEN_WIDTH, SCREEN_HEIGHT) .title("SssBall") //.fullscreen(true) .init();

...

let key = root.wait_for_keypress(true); match key { Key { code: Enter, alt: true, .. } => { // Alt+Enter: toggle fullscreen println!("alt + enter pressed"); root.set_fullscreen(!root.is_fullscreen()); }

Jacktwist avatar Dec 19 '19 22:12 Jacktwist

I had a look at your code, and everything is fine. I also downloaded and compiled/ran your whole github repo (the one you linked) and alt+enter works fine. Although the first time I pressed it, it took some time to get out of fullscreen. I'm using windows 10 with rust v1.37.0

L3nn0x avatar Dec 19 '19 23:12 L3nn0x

I tried moving around and then pressing alt+enter and it's fine as well.

L3nn0x avatar Dec 19 '19 23:12 L3nn0x

Ok @L3nn0x, thanks for checking it out. I thought I was missing something fundamental about the syntax. I'm using Ubuntu 19. If I comment out the .size() in the initialization, alt + enter works.

Jacktwist avatar Dec 23 '19 06:12 Jacktwist

Funny story, I can reproduce this bug on Ubuntu 22.04.

But I tried @Jacktwist 's suggestion, and just commented out the .size() line in the main function. This solves the problem. Except...

  1. It resets the resolution of my monitors on a level I can't even fix via the normal system menus. And nothing short of a reboot fixes it.
  2. The bottom half of the game screen is unrecoverably cut off.

So, that isn't my favorite solution. heh

The bug persists, but it'll be a couple of weeks until I have time to seriously hunt it down.

john-science avatar Nov 11 '22 15:11 john-science

tcod doesn't expose a binding for ffi::TCOD_sys_shutdown(), and doesn't call that function. Thus SDL_Quit is never called to restore the screen resolution. So your screen resolution bug is a separate issue. I think the best fix is probably to use doryen-rs.

softmoth avatar Feb 25 '23 18:02 softmoth