Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Linux framebuffer and input system #15

Merged
merged 2 commits into from
Oct 6, 2024
Merged

Conversation

shengwen-tw
Copy link
Collaborator

@shengwen-tw shengwen-tw commented Jul 24, 2024

This pull request introduces Linux framebuffer backend and mouse event handling for Mado.

To test the introduced feature:

  1. Press Ctrl+Alt+F3 to switch to new virtual terminal.
  2. Run Mado with the following command:
$ sudo ./demo-fbdev

The user should see the following result on the screen:

image

After finished testing, the user can switch back to the desktop with Ctrl+Alt+F1.

Makefile Outdated Show resolved Hide resolved
jserv

This comment was marked as outdated.

backend/fb.c Outdated Show resolved Hide resolved
jserv

This comment was marked as outdated.

@shengwen-tw
Copy link
Collaborator Author

I believe we need to modify the twin_create() interface to support passing device path to the Linux framebuffer backend.
So far, I haven't found an elegant solution for this.
If you have any insights on this issue, please let me know.

@jserv
Copy link
Contributor

jserv commented Jul 27, 2024

I believe we need to modify the twin_create() interface to support passing device path to the Linux framebuffer backend.
So far, I haven't found an elegant solution for this.

Simply use environment variable such as "FRAMEBUFFER".

Copy link
Contributor

@jserv jserv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Always use "fbdev" instead of ambiguous “fb" in all occurrences.

@shengwen-tw
Copy link
Collaborator Author

We can now run sample program with Linux framebuffer using:

sudo FRAMEBUFFER=/dev/fb0 ./demo-fbdev

backend/fbdev.c Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
Makefile Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
Copy link
Contributor

@jserv jserv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refine the callback functions passing to twin_screen_create.

backend/fbdev.c Outdated Show resolved Hide resolved
backend/fbdev.c Show resolved Hide resolved
backend/fbdev.c Outdated Show resolved Hide resolved
jserv

This comment was marked as outdated.

README.md Outdated Show resolved Hide resolved
backend/fbdev.c Outdated Show resolved Hide resolved
jserv

This comment was marked as resolved.

Copy link
Contributor

@jserv jserv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rebase the latest main branch, which contains a preliminary mouse manipulation feature, meaning that the cursor can be rendered along with input events supported via the Linux input subsystem.

@sysprog21 sysprog21 deleted a comment from shengwen-tw Jul 30, 2024
@shengwen-tw
Copy link
Collaborator Author

shengwen-tw commented Aug 12, 2024

It is quite interesting that seems Ubuntu allocates VT2 for Wayland or X11 server (Not sure about other distributions):

$ ps -aux | grep tty
shengwen    1509  0.0  0.0 171148  5376 tty2     Ssl+ 22:33   0:00 /usr/libexec/gdm-wayland-session env GNOME_SHELL_SESSION_MODE=ubuntu /usr/bin/gnome-session --session=ubuntu

This implies that Ctrl+Alt+Fn does not necessary switch to VT n directly.

Also, Ctrl+Alt+F1 is essentially designed for switching to the VT of the desktop graphics environment (i.e., VT2), and Ctrl+Alt+F2 is not assigned with functionality.

Reference: What is the purpose of /usr/lib/xorg/Xorg vt2 -displayfd 3?

@jserv
Copy link
Contributor

jserv commented Aug 12, 2024

This implies that Ctrl+Alt+Fn does not necessary switch to VT n directly.

The composite key to trigger VT switching is not fixed, meaning the behavior can vary significantly between Linux distributions. Mado is not necessarily designed to co-exist with the X server or Wayland display server. Instead, it is intended to operate with the Linux framebuffer, similar to FBUI. You can include a note about VT switching without specifying the exact keystrokes.

backend/fbdev.c Outdated Show resolved Hide resolved
Copy link
Contributor

@jserv jserv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rebase the latest main branch and utilize the logging functions.

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
backend/fbdev.c Outdated Show resolved Hide resolved
@jserv

This comment was marked as outdated.

backend/linux_input.c Outdated Show resolved Hide resolved
return NULL;
}

static bool dummy(int file, twin_file_op_t ops, void *closure)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The dummy is a hack though.

backend/fbdev.c Outdated Show resolved Hide resolved
backend/fbdev.c Outdated Show resolved Hide resolved
#endif

/* Start event handling thread */
if (pthread_create(&tm->evdev_thread, NULL, twin_linux_evdev_thread, tm)) {
Copy link
Contributor

@jserv jserv Sep 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TWIN (and by extension, Mado) was designed to operate in single-threaded environments, and it is not reasonable to assume POSIX threads are available everywhere. Be sure to note the use of POSIX threads in the git commit messages for the Linux framebuffer backend. Coroutines could potentially be used as an alternative.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reference on Coroutine in C:
#4 (comment)

backend/fbdev.c Outdated Show resolved Hide resolved
backend/fbdev.c Show resolved Hide resolved
Copy link
Contributor

@jserv jserv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Append Close #3 at the end of the git commit messages. You should refine the commit message to clearly state what has been accomplished and outline any remaining tasks for further improvements.

This commit adds a Linux framebuffer backend to Mado, utilizing framebuffer
and event devices for basic input and display.

Note that though TWIN (and by extension, Mado) was designed to operate in
single-threaded environments, the Linux framebuffer backend in Mado currently
uses POSIX thread to manage input system events. Coroutines could potentially
be used as an alternative.

Follow-up tasks:
1. Protect mouse event update with mutex (see linux_input.c)
2. Fix an existing unexpected termination bug (see linux_input.c)
3. Support DRM/KMS backend
4. Support hot-pluging and removal of input devices via udev
5. Refine event handling (i.e., remove POSIX thread if possible)

Close sysprog21#3
@jserv jserv merged commit 980bd4c into sysprog21:main Oct 6, 2024
3 checks passed
@jserv
Copy link
Contributor

jserv commented Oct 6, 2024

Thank @shengwen-tw for contributing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants