From e293cf03baf6db248a19b276c630698e56bdb1c9 Mon Sep 17 00:00:00 2001 From: Vincent Wei Date: Mon, 26 Sep 2022 14:06:09 +0800 Subject: [PATCH] fix bugs when virtual window enabled for sa and procs runmodes --- include/customial.h | 49 +++++++++---------- include/gdi.h | 2 +- src/gui/accelkey.c | 1 - src/gui/menu.c | 1 - src/gui/window.c | 10 ++-- src/include/Makefile.am | 2 +- .../{blockheap.h => blockheap.h.deprecated} | 4 +- src/include/internals.h | 4 +- src/include/newgal.h | 2 +- src/kernel/blockheap.c | 14 +++--- src/kernel/desktop-procs.c | 10 +--- src/kernel/desktop-sa.c | 10 +--- src/kernel/desktop-ths.c | 4 +- src/kernel/fixstr.c | 16 +++--- src/kernel/init-lite.c | 2 +- src/kernel/init.c | 4 +- src/kernel/message.c | 19 +++---- src/newgdi/region.c | 2 +- 18 files changed, 69 insertions(+), 87 deletions(-) rename src/include/{blockheap.h => blockheap.h.deprecated} (97%) diff --git a/include/customial.h b/include/customial.h index 4e34b308..20f36d4f 100644 --- a/include/customial.h +++ b/include/customial.h @@ -131,7 +131,31 @@ #define IAL_EVENT_GESTURE_PINCH_UPDATE 0x0084 #define IAL_EVENT_GESTURE_PINCH_END 0x0085 +#define TABLET_TOOL_CHANGED_X (1 << 0) +#define TABLET_TOOL_CHANGED_Y (1 << 1) +#define TABLET_TOOL_CHANGED_PRESSURE (1 << 2) +#define TABLET_TOOL_CHANGED_DISTANCE (1 << 3) +#define TABLET_TOOL_CHANGED_TILT_X (1 << 4) +#define TABLET_TOOL_CHANGED_TILT_Y (1 << 5) +#define TABLET_TOOL_CHANGED_ROTATION (1 << 6) +#define TABLET_TOOL_CHANGED_SLIDER (1 << 7) +#define TABLET_TOOL_CHANGED_SIZE_MAJOR (1 << 8) +#define TABLET_TOOL_CHANGED_SIZE_MINOR (1 << 9) +#define TABLET_TOOL_CHANGED_WHEEL (1 << 10) + #ifndef TABLET_TOOL_X + #define TABLET_TOOL_X 0 + #define TABLET_TOOL_Y 1 + #define TABLET_TOOL_PRESSURE 2 + #define TABLET_TOOL_DISTANCE 3 + #define TABLET_TOOL_TILT_X 4 + #define TABLET_TOOL_TILT_Y 5 + #define TABLET_TOOL_ROTATION 6 + #define TABLET_TOOL_SLIDER 7 + #define TABLET_TOOL_SIZE_MAJOR 8 + #define TABLET_TOOL_SIZE_MINOR 9 + #define TABLET_TOOL_WHEEL 10 + #define TABLET_TOOL_PROXIMITY_STATE_INVALID 0 #define TABLET_TOOL_PROXIMITY_STATE_OUT 1 #define TABLET_TOOL_PROXIMITY_STATE_IN 2 @@ -149,31 +173,6 @@ #define TABLET_PAD_STRIP_SOURCE_UNKNOWN 0 #define TABLET_PAD_STRIP_SOURCE_FINGER 1 - - #define TABLET_TOOL_CHANGED_X (1 << 0) - #define TABLET_TOOL_CHANGED_Y (1 << 1) - #define TABLET_TOOL_CHANGED_PRESSURE (1 << 2) - #define TABLET_TOOL_CHANGED_DISTANCE (1 << 3) - #define TABLET_TOOL_CHANGED_TILT_X (1 << 4) - #define TABLET_TOOL_CHANGED_TILT_Y (1 << 5) - #define TABLET_TOOL_CHANGED_ROTATION (1 << 6) - #define TABLET_TOOL_CHANGED_SLIDER (1 << 7) - #define TABLET_TOOL_CHANGED_SIZE_MAJOR (1 << 8) - #define TABLET_TOOL_CHANGED_SIZE_MINOR (1 << 9) - #define TABLET_TOOL_CHANGED_WHEEL (1 << 10) - - #define TABLET_TOOL_X 0 - #define TABLET_TOOL_Y 1 - #define TABLET_TOOL_PRESSURE 2 - #define TABLET_TOOL_DISTANCE 3 - #define TABLET_TOOL_TILT_X 4 - #define TABLET_TOOL_TILT_Y 5 - #define TABLET_TOOL_ROTATION 6 - #define TABLET_TOOL_SLIDER 7 - #define TABLET_TOOL_SIZE_MAJOR 8 - #define TABLET_TOOL_SIZE_MINOR 9 - #define TABLET_TOOL_WHEEL 10 - #endif #define IAL_EVENT_TABLET_TOOL_AXIS 0x0090 diff --git a/include/gdi.h b/include/gdi.h index e3a1e938..2645adfd 100644 --- a/include/gdi.h +++ b/include/gdi.h @@ -587,7 +587,7 @@ enum { * \sa InitBlockDataHeap, DestroyBlockDataHeap */ typedef struct _BLOCKHEAP { -#ifdef _MGRM_THREADS +#ifdef _MGHAVE_VIRTUAL_WINDOW pthread_mutex_t lock; #endif /** Size of one block element in bytes. */ diff --git a/src/gui/accelkey.c b/src/gui/accelkey.c index 643e9eca..1bf47d2c 100644 --- a/src/gui/accelkey.c +++ b/src/gui/accelkey.c @@ -59,7 +59,6 @@ #include "cliprect.h" #include "gal.h" #include "internals.h" -#include "blockheap.h" #include "accelkey.h" static BLOCKHEAP ACHeap; diff --git a/src/gui/menu.c b/src/gui/menu.c index f76c2ad4..4168c03c 100644 --- a/src/gui/menu.c +++ b/src/gui/menu.c @@ -71,7 +71,6 @@ #include "cliprect.h" #include "gal.h" #include "internals.h" -#include "blockheap.h" #include "menu.h" #define SHORTEN 0 diff --git a/src/gui/window.c b/src/gui/window.c index 9ca18737..acb35683 100644 --- a/src/gui/window.c +++ b/src/gui/window.c @@ -3784,16 +3784,15 @@ static void* _message_thread_entry (void* arg) goto failed; /* create message queue for this thread */ - if (!(entry_args.msg_queue = mg_AllocMsgQueueForThisThread ())) + if (!(entry_args.msg_queue = mg_AllocMsgQueueForThisThread (FALSE))) goto failed; orig_args->msg_queue = entry_args.msg_queue; sem_post (entry_args.wait); - /* handle in mg_AllocMsgQueueForThisThread + /* register the message queue */ SendMessage (HWND_DESKTOP, MSG_MANAGE_MSGTHREAD, MSGTHREAD_SIGNIN, (LPARAM)&entry_args.msg_queue); - */ if (pthread_setcancelstate (PTHREAD_CANCEL_ENABLE, NULL)) goto cancelled; @@ -3801,11 +3800,10 @@ static void* _message_thread_entry (void* arg) /* call start routine of app */ entry_args.start_routine (entry_args.arg); - /* handle in mg_FreeMsgQueueForThisThread + /* unregister the message queue */ SendMessage (HWND_DESKTOP, MSG_MANAGE_MSGTHREAD, MSGTHREAD_SIGNOUT, (LPARAM)&entry_args.msg_queue); - */ - mg_FreeMsgQueueForThisThread (); + mg_FreeMsgQueueForThisThread (FALSE); return NULL; diff --git a/src/include/Makefile.am b/src/include/Makefile.am index ed244d0f..a8efbb4f 100644 --- a/src/include/Makefile.am +++ b/src/include/Makefile.am @@ -3,7 +3,7 @@ noinst_HEADERS = \ cursor.h dc.h event.h list.h element.h \ ial.h inline.h internals.h zorder.h menu.h misc.h \ msgstr.h sysfont.h timer.h devfont.h fontname.h \ - readbmp.h icon.h blockheap.h rbtree.h \ + readbmp.h icon.h rbtree.h \ ourhdr.h client.h server.h sharedres.h sockio.h drawsemop.h \ gal.h newgal.h memops.h incoreres.h sysres.h clipboard.h \ glyph.h license.h mgsock.h unicode-ops.h \ diff --git a/src/include/blockheap.h b/src/include/blockheap.h.deprecated similarity index 97% rename from src/include/blockheap.h rename to src/include/blockheap.h.deprecated index 1d2030c3..6379e36d 100644 --- a/src/include/blockheap.h +++ b/src/include/blockheap.h.deprecated @@ -47,6 +47,8 @@ ** blockheap.h: the head file of heap for block data. ** ** Create date: 2001/01/10 +** +** DEPRECATED, USE window.h INSTEAD. */ #ifndef GUI_BLOCKHEAP_H @@ -55,7 +57,7 @@ #ifndef _MGUI_GDI_H /* included in include/gdi.h */ struct _BLOCKHEAP { -#ifdef _MGRM_THREADS +#ifdef _MGHAVE_VIRTUAL_WINDOW pthread_mutex_t lock; #endif /* Size of one block element. */ diff --git a/src/include/internals.h b/src/include/internals.h index 2f33d5a3..be9cfd4a 100644 --- a/src/include/internals.h +++ b/src/include/internals.h @@ -772,8 +772,8 @@ static inline PMSGQUEUE getMsgQueue (HWND hWnd) } -MSGQUEUE* mg_AllocMsgQueueForThisThread (void); -void mg_FreeMsgQueueForThisThread (void); +MSGQUEUE* mg_AllocMsgQueueForThisThread (BOOL sign_in); +void mg_FreeMsgQueueForThisThread (BOOL sign_off); /* Since 5.0.0 */ int __mg_throw_away_messages (PMSGQUEUE pMsgQueue, HWND hWnd); diff --git a/src/include/newgal.h b/src/include/newgal.h index 675da4e0..ba40378e 100644 --- a/src/include/newgal.h +++ b/src/include/newgal.h @@ -56,8 +56,8 @@ #define GUI_NEWGAL_H #include "gdi.h" +#include "window.h" #include "constants.h" -#include "blockheap.h" #if IS_COMPOSITING_SCHEMA #include diff --git a/src/kernel/blockheap.c b/src/kernel/blockheap.c index 9eecc3a9..33c8242d 100644 --- a/src/kernel/blockheap.c +++ b/src/kernel/blockheap.c @@ -59,13 +59,13 @@ #include "common.h" #include "minigui.h" #include "gdi.h" +#include "window.h" #include "constants.h" -#include "blockheap.h" #include "misc.h" BOOL InitBlockDataHeap (PBLOCKHEAP heap, size_t sz_block, size_t sz_heap) { -#ifdef _MGRM_THREADS +#ifdef _MGHAVE_VIRTUAL_WINDOW pthread_mutex_init (&heap->lock, NULL); #endif @@ -99,7 +99,7 @@ void* BlockDataAlloc (PBLOCKHEAP heap) int free_slot; unsigned char* block_data = NULL; -#ifdef _MGRM_THREADS +#ifdef _MGHAVE_VIRTUAL_WINDOW pthread_mutex_lock (&heap->lock); #endif @@ -118,7 +118,7 @@ void* BlockDataAlloc (PBLOCKHEAP heap) ret: -#ifdef _MGRM_THREADS +#ifdef _MGHAVE_VIRTUAL_WINDOW pthread_mutex_unlock (&heap->lock); #endif return block_data; @@ -128,7 +128,7 @@ void BlockDataFree (PBLOCKHEAP heap, void* data) { unsigned char* block_data = data; -#ifdef _MGRM_THREADS +#ifdef _MGHAVE_VIRTUAL_WINDOW pthread_mutex_lock (&heap->lock); #endif @@ -146,7 +146,7 @@ void BlockDataFree (PBLOCKHEAP heap, void* data) heap, slot); } -#ifdef _MGRM_THREADS +#ifdef _MGHAVE_VIRTUAL_WINDOW pthread_mutex_unlock (&heap->lock); #endif } @@ -193,7 +193,7 @@ void DestroyBlockDataHeap (PBLOCKHEAP heap) free (heap->usage_bmp); heap->usage_bmp = NULL; -#ifdef _MGRM_THREADS +#ifdef _MGHAVE_VIRTUAL_WINDOW pthread_mutex_destroy (&heap->lock); #endif } diff --git a/src/kernel/desktop-procs.c b/src/kernel/desktop-procs.c index aa34c26d..7daaafe7 100644 --- a/src/kernel/desktop-procs.c +++ b/src/kernel/desktop-procs.c @@ -231,14 +231,6 @@ static void init_desktop_win (void) BOOL mg_InitDesktop (void) { -#if 0 /* move to init-lite.c */ - /* Since 5.0.0: allocate message queue for desktop thread */ - if (!(__mg_dsk_msg_queue = mg_AllocMsgQueueForThisThread ()) ) { - _WRN_PRINTF ("failed to allocate message queue\n"); - return FALSE; - } -#endif /* moved code */ - #ifndef _MGSCHEMA_COMPOSITING /* Init heap of clipping rects. */ InitFreeClipRectList (&sg_FreeClipRectList, SIZE_CLIPRECTHEAP); @@ -259,7 +251,7 @@ BOOL mg_InitDesktop (void) void mg_TerminateDesktop (void) { /* Since 5.0.0: message queue for desktop thread was dynamically allocated */ - mg_FreeMsgQueueForThisThread (); + mg_FreeMsgQueueForThisThread (TRUE); __mg_dsk_msg_queue = NULL; #ifndef _MGSCHEMA_COMPOSITING diff --git a/src/kernel/desktop-sa.c b/src/kernel/desktop-sa.c index f60ba488..fffa09e7 100644 --- a/src/kernel/desktop-sa.c +++ b/src/kernel/desktop-sa.c @@ -102,14 +102,6 @@ BOOL mg_InitDesktop (void) int ret; RECT rcScr = GetScreenRect(); -#if 0 /* move to init-lite.c */ - /* Since 5.0.0: allocate message queue for desktop thread */ - if (!(__mg_dsk_msg_queue = mg_AllocMsgQueueForThisThread ()) ) { - _WRN_PRINTF ("failed to allocate message queue\n"); - return FALSE; - } -#endif /* moved code */ - /* * Init ZOrderInfo here. */ @@ -153,7 +145,7 @@ BOOL mg_InitDesktop (void) void mg_TerminateDesktop (void) { if (__mg_dsk_msg_queue) { - mg_FreeMsgQueueForThisThread (); + mg_FreeMsgQueueForThisThread (TRUE); __mg_dsk_msg_queue = NULL; } diff --git a/src/kernel/desktop-ths.c b/src/kernel/desktop-ths.c index e97ad44e..1068a87e 100644 --- a/src/kernel/desktop-ths.c +++ b/src/kernel/desktop-ths.c @@ -145,7 +145,7 @@ void* __kernel_desktop_main (void* data) MSG Msg; /* init message queue of desktop thread */ - if (!(__mg_dsk_msg_queue = mg_AllocMsgQueueForThisThread ()) ) { + if (!(__mg_dsk_msg_queue = mg_AllocMsgQueueForThisThread (TRUE)) ) { _ERR_PRINTF ("failed to allocate message queue\n"); sem_post ((sem_t*)data); return NULL; @@ -191,7 +191,7 @@ void* __kernel_desktop_main (void* data) #endif } - mg_FreeMsgQueueForThisThread (); + mg_FreeMsgQueueForThisThread (TRUE); __mg_dsk_msg_queue = NULL; return NULL; } diff --git a/src/kernel/fixstr.c b/src/kernel/fixstr.c index da02de0c..5220f80d 100644 --- a/src/kernel/fixstr.c +++ b/src/kernel/fixstr.c @@ -66,7 +66,7 @@ static struct FIXSTR { BYTE bitmap[LEN_BITMAP]; int offset[NR_HEAP]; char* heap[NR_HEAP + 1]; -#ifdef _MGRM_THREADS +#ifdef _MGHAVE_VIRTUAL_WINDOW pthread_mutex_t lock; #endif } FixStrHeap; @@ -98,7 +98,7 @@ BOOL mg_InitFixStr (void) offset += 1<> j)) { *bitmap &= (~(0x80 >> j)); -#ifdef _MGRM_THREADS +#ifdef _MGHAVE_VIRTUAL_WINDOW pthread_mutex_unlock (&FixStrHeap.lock); #endif #if 0 @@ -181,7 +181,7 @@ char* GUIAPI FixStrAlloc (int len) bitmap++; } -#ifdef _MGRM_THREADS +#ifdef _MGHAVE_VIRTUAL_WINDOW pthread_mutex_unlock (&FixStrHeap.lock); #endif return (char*)malloc (len + 1); @@ -216,7 +216,7 @@ void GUIAPI FreeFixStr (char* str) // if i == 0; then bufflen = 512 bufflen = 1 << (NR_HEAP + 1 - i); -#ifdef _MGRM_THREADS +#ifdef _MGHAVE_VIRTUAL_WINDOW pthread_mutex_lock (&FixStrHeap.lock); #endif heap = FixStrHeap.heap[i]; @@ -236,7 +236,7 @@ void GUIAPI FreeFixStr (char* str) bitmap = bitmap + (stroff>>3); *bitmap |= (0x80 >> (stroff%8)); -#ifdef _MGRM_THREADS +#ifdef _MGHAVE_VIRTUAL_WINDOW pthread_mutex_unlock (&FixStrHeap.lock); #endif } diff --git a/src/kernel/init-lite.c b/src/kernel/init-lite.c index 6c2b7f69..4c650f0a 100644 --- a/src/kernel/init-lite.c +++ b/src/kernel/init-lite.c @@ -386,7 +386,7 @@ int InitGUI (int argc, const char* agr[]) /* Since 5.0.0 allocate message queue for desktop thread before starting client. */ - if (!(__mg_dsk_msg_queue = mg_AllocMsgQueueForThisThread ()) ) { + if (!(__mg_dsk_msg_queue = mg_AllocMsgQueueForThisThread (TRUE)) ) { err_message (step, "Failed to allocate message queue!"); return step; } diff --git a/src/kernel/init.c b/src/kernel/init.c index df113f47..c05f9dd8 100644 --- a/src/kernel/init.c +++ b/src/kernel/init.c @@ -578,7 +578,7 @@ int GUIAPI InitGUI (int args, const char *agr[]) /* init message queue of main GUI thread */ step++; - if (!(msg_queue = mg_AllocMsgQueueForThisThread ())) { + if (!(msg_queue = mg_AllocMsgQueueForThisThread (TRUE))) { _ERR_PRINTF ("KERNEL>InitGUI: failed to allocate message queue!\n"); goto failure; } @@ -655,7 +655,7 @@ void GUIAPI TerminateGUI (int not_used) miFreeArcCache (); #endif - mg_FreeMsgQueueForThisThread (); + mg_FreeMsgQueueForThisThread (TRUE); deleteThreadInfoKey (); diff --git a/src/kernel/message.c b/src/kernel/message.c index e91ce13f..7937927b 100644 --- a/src/kernel/message.c +++ b/src/kernel/message.c @@ -60,7 +60,6 @@ #include "gdi.h" #include "window.h" -#include "blockheap.h" #include "cliprect.h" #include "gal.h" #include "internals.h" @@ -159,7 +158,7 @@ void mg_DestroyFreeQMSGList (void) pthread_key_t __mg_threadinfo_key; #endif -MSGQUEUE* mg_AllocMsgQueueForThisThread (void) +MSGQUEUE* mg_AllocMsgQueueForThisThread (BOOL sign_in) { MSGQUEUE* pMsgQueue; @@ -177,13 +176,14 @@ MSGQUEUE* mg_AllocMsgQueueForThisThread (void) pthread_setspecific (__mg_threadinfo_key, pMsgQueue); #endif - // register this new message queue - SendMessage (HWND_DESKTOP, MSG_MANAGE_MSGTHREAD, - MSGTHREAD_SIGNIN, (LPARAM)pMsgQueue); + if (sign_in) { + SendMessage (HWND_DESKTOP, MSG_MANAGE_MSGTHREAD, + MSGTHREAD_SIGNIN, (LPARAM)pMsgQueue); + } return pMsgQueue; } -void mg_FreeMsgQueueForThisThread (void) +void mg_FreeMsgQueueForThisThread (BOOL sign_off) { MSGQUEUE* pMsgQueue; @@ -194,9 +194,10 @@ void mg_FreeMsgQueueForThisThread (void) _WRN_PRINTF ("there are still some windows not destroyed\n"); } - // unregister this message queue - SendMessage (HWND_DESKTOP, MSG_MANAGE_MSGTHREAD, - MSGTHREAD_SIGNOUT, (LPARAM)pMsgQueue); + if (sign_off) { + SendMessage (HWND_DESKTOP, MSG_MANAGE_MSGTHREAD, + MSGTHREAD_SIGNOUT, (LPARAM)pMsgQueue); + } mg_DestroyMsgQueue (pMsgQueue); free (pMsgQueue); diff --git a/src/newgdi/region.c b/src/newgdi/region.c index 31f02a64..8a7a0e95 100644 --- a/src/newgdi/region.c +++ b/src/newgdi/region.c @@ -138,9 +138,9 @@ SOFTWARE. #include "common.h" #include "gdi.h" +#include "window.h" #include "cliprect.h" #include "gal.h" -#include "blockheap.h" typedef void (*voidProcp1)(CLIPRGN *region, const CLIPRECT *r1, const CLIPRECT *r1End, const CLIPRECT *r2, const CLIPRECT *r2End, int top, int bottom);