8000 Go back to windowed mode don't work · Issue #1280 · ggez/ggez · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Go back to windowed mode don't work #1280
Open
@buxx

Description

@buxx

Describe the bug

When I use ctx.gfx.set_mode to get back from fullscreen, It don't work.

To Reproduce

With following source code, press F11. Fullscreen will be enabled. Press F11 again, Fullscreen is removed. Press F11. Fullscreen will be enabled. Press F11 again, Fullscreen still here.

//! The simplest possible example that does something.
#![allow(clippy::unnecessary_wraps)]

use ggez::{
    conf::{FullscreenType, WindowMode},
    event,
    glam::*,
    graphics::{self, Color},
    input::keyboard::{KeyCode, KeyInput},
    Context, GameError, GameResult,
};

struct MainState {
    pos_x: f32,
    circle: graphics::Mesh,
    is_fullscreen: bool,
}

pub fn fullscreen_mode() -> WindowMode {
    WindowMode::default().fullscreen_type(FullscreenType::Desktop)
}

pub fn windowed_mode() -> WindowMode {
    WindowMode::default()
        .dimensions(1024., 768.)
        .maximized(false)
        .resizable(true)
}

impl MainState {
    fn new(ctx: &mut Context) -> GameResult<MainState> {
        let circle = graphics::Mesh::new_circle(
            ctx,
            graphics::DrawMode::fill(),
            vec2(0., 0.),
            100.0,
            2.0,
            Color::WHITE,
        )?;

        Ok(MainState {
            pos_x: 0.0,
            circle,
            is_fullscreen: false,
        })
    }
}

impl event::EventHandler<ggez::GameError> for MainState {
    fn update(&mut self, _ctx: &mut Context) -> GameResult {
        self.pos_x = self.pos_x % 800.0 + 1.0;
        Ok(())
    }

    fn draw(&mut self, ctx: &mut Context) -> GameResult {
        let mut canvas =
            graphics::Canvas::from_frame(ctx, graphics::Color::from([0.1, 0.2, 0.3, 1.0]));

        canvas.draw(&self.circle, Vec2::new(self.pos_x, 380.0));

        canvas.finish(ctx)?;

        Ok(())
    }

    fn key_up_event(&mut self, ctx: &mut Context, input: KeyInput) -> Result<(), GameError> {
        match input.keycode {
            Some(KeyCode::F11) => {
                if self.is_fullscreen {
                    println!("SET WINDOWED");
                    if let Err(error) = ctx.gfx.set_mode(windowed_mode()) {
                        eprintln!("ERROR : when set windowed mode: {}", error);
                    }
                    self.is_fullscreen = false;
                } else {
                    println!("SET FULLSCREEN");
                    if let Err(error) = ctx.gfx.set_mode(fullscreen_mode()) {
                        eprintln!("ERROR : when set fullscreen mode: {}", error);
                    }
                    self.is_fullscreen = true;
                }
            }
            _ => {}
        };
        GameResult::Ok(())
    }
}

pub fn main() -> GameResult {
    let cb = ggez::ContextBuilder::new("super_simple", "ggez");
    let (mut ctx, event_loop) = cb.build()?;
    let state = MainState::new(&mut ctx)?;
    event::run(ctx, event_loop, state)
}

Expected behavior

Windowed mode should work every time.

Hardware and Software:

  • ggez version: 0.9.3
  • OS: Ubuntu 20.04.6 LTS
  • Graphics card:
 *-display                 
      description: VGA compatible controller
      produit: Intel Corporation
      fabricant: Intel Corporation
      identifiant matériel: 2
      information bus: pci@0000:00:02.0
      nom logique: /dev/fb0
      version: 01
      bits: 64 bits
      horloge: 33MHz
      fonctionnalités: pciexpress msi pm vga_controller bus_master cap_list rom fb
      configuration : depth=32 driver=i915 latency=0 mode=1920x1080 visual=truecolor xres=1920 yres=1080
      ressources : mémoireE/S:600-5ff mémoireE/S:400-3ff irq:157 mémoire:6052000000-6052ffffff mémoire:4000000000-400fffffff portE/S:3000(taille=64) mémoire:c0000-dffff mémoire:4010000000-4016ffffff mémoire:4020000000-40fffff
  • Graphics card drivers: default

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0