soegaard / sketching

A Racket library for creative drawings and animations. Inspired by Processing.
110 stars 10 forks source link

Click to focus windows, also on desktop #93

Closed Munksgaard closed 1 year ago

Munksgaard commented 1 year ago

While I understand that there may be technical reasons for the "click-to-focus" requirement before a sketching program starts reacting to input in the browser, I don't see why it is necessary on the desktop? Indeed, if I create a full-screen desktop window with sketching, it seems a bit strange that I have to click it first before I can start typing?

soegaard commented 1 year ago

Hej @Munksgaard

I agree, that a full screen window should get focus automatically, so the fullscreen command now does that.

Commit: e7c2bdc

I believe an raco pkg update sketching should give you an updated version.

Tak for forslaget.

Munksgaard commented 1 year ago

Hej @soegaard,

Thanks for the quick reply. I think I've updated sketching, here's the output of raco pkg show sketching:

Installation-wide:
 [none]
User-specific for installation "8.6":
 Package    Checksum                Source
 sketching  e7c2bdc6fe50edbf829...  catalog...etching#main

However, I still don't seem to get focus when running a fullscreen app. Here's my program:

#lang sketching

(define (setup)
  (fullscreen)
  (no-stroke)
  (color-mode 'hsb 360 100 100))

(define (on-key-pressed)
  (fill (random 0 360) 100 100)
  (circle (random 0 width) (random 0 height) (random 10 200)))

(define (draw) (void))

I'm new to racket, so I apologize in advance if I've overlooked something trivial.


Det var så lidt :-)

soegaard commented 1 year ago

@Munksgaard I don't think, you overlooked anything. The hash shows you have the newest version. Your program works as intended on macOS - I'll try to find someone to test the on Linux in the Racket Discord (if lucky maybe even nixOS).

soegaard commented 1 year ago

A little progress. I wrote a test program using racket/gui (without Sketching) that shows the same behaviour (i.e. the new fullscreen window doesn't get focus).

However, I am beginning to think this is not a bug in racket/gui but up to the window manager used. I tested on Ubuntu and the program gsettings reveals two keys focus-mode and focus-new-windows with default values click and smart respectively.

Their meanings are:

Key: focus-mode Deafult: click' Summary: Window focus mode Description: The window focus mode indicates how windows are activated. It has three possible values; “click” means windows must be clicked in order to focus them, “sloppy” means windows are focused when the mouse enters the window, and “mouse” means windows are focused when the mouse enters the window and unfocused when the mouse leaves the window.

Key: focus-new-windows Default: smart Summart: Control how new windows get focus Description: This option provides additional control over how newly created windows get focus. It has two possible values; “smart” applies the user’s normal focus mode, and “strict” results in windows started from a terminal not being given focus.

Similarly xfce4 has an setting "Activate focus stealing prevention".

On Gnome on Ubuntu I used the command below to see the settings:

gsettings list-recursively org.gnome.desktop.wm.preferences

And to save it somewhere, the test program was:

#lang racket
(require racket/gui)

(define key-canvas%
  (class canvas%
    (super-new)
    (define key #f)

    (define/override (on-char e)
      (define pressed?    (eq? (send e get-key-release-code) 'press))
      (define key-pressed (and pressed? (send e get-key-code)))
      (set! key key-pressed)
      (send this on-paint))

    (define/override (on-paint)      
      (when key
        (displayln key)
        (define dc (send this get-dc))
        (send dc clear)
        (send dc draw-text (string key) 90 90)
        (set! key #f)))))

(define f (new frame%
               [label "Full Focus"]
               [width  200]
               [height 200]
               [style  (list 'fullscreen-button)]))

(define c (new key-canvas% [parent f]))

(send f show #t)
(define (stop) (send f show #f))
(define (full)
  (send f fullscreen #t)
  (send f focus))
Munksgaard commented 1 year ago

Interesting! But surely, fullscreen receiving focus is a pretty normal thing? I don't think I've experienced problems anywhere else?

I just tried the breakout example from Bevy, the rust game engine (as documented here), and it doesn't seem to have any problems grabbing input immediately, even for non-fullscreen apps.

soegaard commented 1 year ago

Which window manager are you using?

Munksgaard commented 1 year ago

Sway

soegaard commented 1 year ago

I tried googling: wayland focus

The results are confusing at best.

Munksgaard commented 1 year ago

Yeah, it might have something to do with wayland. I suggest not spending too much time on it.