Acfboy commented on issue #18566:
URL: https://github.com/apache/nuttx/issues/18566#issuecomment-4781655959

   Sorry for the slow progress this week — I got stuck on two strange bugs 
while testing `mwdemo.c` more carefully.
   
   ## 1. Cursor ghosting when running mwin in NuttX
   
   This cost me three afternoons of self-doubt, because I checked the whole 
mouse display pipeline and everything seemed perfectly correct, but the mouse 
was leaving a ghost image when moving. 
   
   However, at one moment I suddenly realised that the ghost colour seemed 
different from the new mouse colour. The ghost colour (RGB) was 0x000080, while 
the mouse colour should be 0x0000FF (they look similar enough blue that I 
hadn’t noticed at all), and the default background colour was 0x008080. That 
made me realise an integer might be getting truncated. So the background is 
reset to 0x000080 instead of 0x008080,  which is the cursor ghosting.
   
   (P.S. Actually the mouse cursor colour was not blue at all, and the 
background colour was wrong too. I noticed those but thought they were another 
bug, which kept me from immediately realising it was a type issue.)
   
   I soon found the problem:  
   [code 
premalink](https://github.com/ghaerr/microwindows/blob/73bb67cf9c864a30935185fca3d5c264e41d2396/src/engine/devmouse.c#L615)
   ```c
   oldcolor = psd->ReadPixel(psd, x, y);
   ```
   Here the type on the left-hand side is `MWPIXELVALHW` and on the right-hand 
side is `MWPIXELVAL`. One is defined as `unsigned char`, the other as `unsigned 
int`.
   
   Then I tracked down where `MWPIXELVALHW` is defined:  
   [code 
premalink](https://github.com/ghaerr/microwindows/blob/73bb67cf9c864a30935185fca3d5c264e41d2396/src/include/mwtypes.h#L228-L246)
   ```c
   #if defined(__AS386_16__) || defined(ELKS)
   /* Force 8 bit palettized display for ELKS*/
   #undef MWPIXEL_FORMAT
   #define MWPIXEL_FORMAT       MWPF_PALETTE
   #endif
   
   #if (MWPIXEL_FORMAT == MWPF_TRUECOLOR565) || (MWPIXEL_FORMAT == 
MWPF_TRUECOLOR555)
   typedef unsigned short MWPIXELVALHW;
   #else
     #if (MWPIXEL_FORMAT == MWPF_TRUECOLOR332) || (MWPIXEL_FORMAT == 
MWPF_TRUECOLOR233)
     typedef unsigned char MWPIXELVALHW;
     #else
       #if MWPIXEL_FORMAT == MWPF_PALETTE
       typedef unsigned char MWPIXELVALHW;
       #else
         typedef uint32_t MWPIXELVALHW;
       #endif
     #endif
   #endif
   ```
   
   When the `ELKS` macro is defined, `MWPIXEL_FORMAT` becomes `MWPF_PALETTE`, 
so `MWPIXELVALHW` is `unsigned char`. And we happened to define `-DELKS=0`! It 
looks like `defined(ELKS)` is a mistake. That way, whenever `ELKS` is defined 
at all (even as 0), this branch is enabled, which is not the intended behaviour 
— defining it as 0 was meant to disable it. I searched the whole project and 
this is the only place where `defined(ELKS)` appears; everywhere else uses `#if 
ELKS`.
   
   Fun fact: I did a git blame and found that the `#if ELKS` usage was written 
back in 2005, while the `defined(ELKS)` appeared at the end of 2025. A 20‑year 
oversight, quite forgivable. This is truly a great project @ghaerr  — it has 
lived longer than I have!
   
   ## 2. Whole system stops after I touch the caption bar
   
   I found that when I click the caption bar, the entire system freezes. Soon I 
discovered that this happens because during dragging, `MwSelect` switches to 
polling — that is, `select()` with `timeout=0`. At this point, the thread in 
NuttX that handles USB input has a lower priority than our application by 
default, so it never gets the CPU, and no events would come. This leaves me 
with a question: why is `CONFIG_HIDMOUSE_DEFPRIO` 50 by default, while the 
launched application's default priority is 100? Should a peripheral's priority 
be lower than the application's? I'm not very familiar with RTOS usage — I'd 
like to know whether I should adjust my configuration or if this default value 
should be changed. @ppisa 
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to