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

Refine event handling #67

Merged
merged 1 commit into from
Nov 20, 2024
Merged

Refine event handling #67

merged 1 commit into from
Nov 20, 2024

Conversation

alanjian85
Copy link
Collaborator

This commit adds a member function for event handling to the backend interface, replacing the previous file-based system that relies on poll(2). The new design addresses issues created by backends like SDL, which do not expose underlying file descriptors. Integrating the fbdev backend into the updated interface remains to be completed.

include/twin.h Outdated Show resolved Hide resolved
@jserv
Copy link
Contributor

jserv commented Oct 31, 2024

Consider the further cleanups:

--- a/include/twin.h
+++ b/include/twin.h
@@ -455,15 +455,10 @@ typedef twin_time_t (*twin_timeout_proc_t)(twin_time_t now, void *closure);
 
 typedef bool (*twin_work_proc_t)(void *closure);
 
-typedef enum _twin_file_op { TWIN_READ = 1, TWIN_WRITE = 2 } twin_file_op_t;
-
-typedef bool (*twin_file_proc_t)(int file, twin_file_op_t ops, void *closure);
-
 #define twin_time_compare(a, op, b) (((a) - (b)) op 0)
 
 typedef struct _twin_timeout twin_timeout_t;
 typedef struct _twin_work twin_work_t;
-typedef struct _twin_file twin_file_t;
 
 /*
  * Widgets
@@ -656,17 +651,6 @@ void twin_premultiply_alpha(twin_pixmap_t *px);
 
 void twin_event_enqueue(const twin_event_t *event);
 
-/*
- * file.c
- */
-
-twin_file_t *twin_set_file(twin_file_proc_t file_proc,
-                           int file,
-                           twin_file_op_t ops,
-                           void *closure);
-
-void twin_clear_file(twin_file_t *file);
-
 /*
  * fixed.c
  */
--- a/include/twin_private.h
+++ b/include/twin_private.h
@@ -472,14 +472,6 @@ struct _twin_work {
     void *closure;
 };
 
-struct _twin_file {
-    twin_queue_t queue;
-    int file;
-    twin_file_op_t ops;
-    twin_file_proc_t proc;
-    void *closure;
-};
-
 typedef enum _twin_order {
     TWIN_BEFORE = -1,
     TWIN_AT = 0,
@@ -504,8 +496,6 @@ twin_queue_t *_twin_queue_set_order(twin_queue_t **head);
 
 void _twin_queue_review_order(twin_queue_t *first);
 
-int _twin_run_file(twin_time_t delay);
-
 void _twin_run_timeout(void);
 
 twin_time_t _twin_timeout_delay(void);

@alanjian85 alanjian85 force-pushed the main branch 2 times, most recently from 5dc19f7 to 7969441 Compare October 31, 2024 12:07
@shengwen-tw
Copy link
Collaborator

I noticed you removed the dummy() function I added as a temporary workaround previously.
Were you able to identify the root cause of the original issue?

src/dispatch.c Outdated Show resolved Hide resolved
@alanjian85
Copy link
Collaborator Author

@shengwen-tw The entire application is driven by twin_dispatch(), which calls _twin_run_file() repeatedly in a loop. When the function cannot discover any files in the queue, it simply terminates the dispatch loop and sleeps for a certain amount of seconds. As a result, after updating the dispatch loop to use the new polling method, it is no longer necessary to create a dummy file for fbdev.

void twin_dispatch(void)
{
    for (;;) {
        _twin_run_timeout();
        _twin_run_work();
        if (!_twin_run_file(_twin_timeout_delay()))
            break;
    }
}

jserv

This comment was marked as duplicate.

@jserv

This comment was marked as resolved.

@alanjian85

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.

Since the backend interface has been changed, the recently-introduced VNC backend implementation should be modified for its poll operation accordingly.

@jserv
Copy link
Contributor

jserv commented Nov 20, 2024

Why did you close this pull request?

@alanjian85
Copy link
Collaborator Author

The previous commit was temporarily removed during the rebase process, which caused Git to close this PR automatically. I will push the new commit once the rebase is fully completed.

This commit adds a member function for event handling to the backend
interface, replacing the previous file-based system that relies on
poll(2). The new design addresses issues created by backends like SDL,
which do not expose underlying file descriptors.

Close sysprog21#4
@alanjian85 alanjian85 reopened this Nov 20, 2024
@jserv
Copy link
Contributor

jserv commented Nov 20, 2024

@ndsl7109256, Can you confirm the proposed changes with VNC backend?

@alanjian85
Copy link
Collaborator Author

I also encountered the issues described in #62 and #65 while debugging the fbdev backend, which resulted in the framebuffer being entirely filled with white. Resolving these problems is critical to continue development on platforms with newer generations of Intel CPUs.

$ lscpu
Architecture:             x86_64
  CPU op-mode(s):         32-bit, 64-bit
  Address sizes:          39 bits physical, 48 bits virtual
  Byte Order:             Little Endian
CPU(s):                   12
  On-line CPU(s) list:    0-11
Vendor ID:                GenuineIntel
  Model name:             13th Gen Intel(R) Core(TM) i7-1355U
    CPU family:           6
    Model:                186
    Thread(s) per core:   2
    Core(s) per socket:   10
    Socket(s):            1
    Stepping:             3
    CPU(s) scaling MHz:   28%
    CPU max MHz:          5000.0000
    CPU min MHz:          400.0000
    BogoMIPS:             5222.40

@ndsl7109256
Copy link
Collaborator

@jserv The VNC backend uses the nvnc_set_pointer_fn API to handle pointer events. Originally, it set file handler with a dummy function similar to the approach used in Fbdev. I believe the proposed change is appropriate and it tests well.

@jserv jserv merged commit b458e28 into sysprog21:main Nov 20, 2024
6 checks passed
@jserv
Copy link
Contributor

jserv commented Nov 20, 2024

Thank @alanjian85 for contributing!

@jserv
Copy link
Contributor

jserv commented Nov 23, 2024

I also encountered the issues described in #62 and #65 while debugging the fbdev backend, which resulted in the framebuffer being entirely filled with white. Resolving these problems is critical to continue development on platforms with newer generations of Intel CPUs.

After merging #65 and #70, the Linux framebuffer backend should be more usable. @alanjian85, please review the recent codebase.

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.

5 participants