tune implementation of MSG_ENDSESSION for THS runmode

This commit is contained in:
Vincent Wei
2020-03-11 19:22:34 +08:00
parent 0059a3226c
commit 666aeea115
4 changed files with 33 additions and 230 deletions

View File

@@ -169,7 +169,8 @@ tab2space() {
# sed -i 's/\<GetSubDCInSecondaryDC\>/GetDCInSecondarySurface/g' `grep '\<GetSubDCInSecondaryDC\>' -rl include/ src/`
sed -i 's/\<checkAndGetMainWindowPtrOfMainWin\>/checkAndGetMainWinIfMainWin/g' `grep '\<checkAndGetMainWindowPtrOfMainWin\>' -rl include/ src/`
sed -i 's/\<checkAndGetMainWindowPtrOfControl\>/checkAndGetMainWinIfWindow/g' `grep '\<checkAndGetMainWindowPtrOfControl\>' -rl include/ src/`
# sed -i 's/\<checkAndGetMainWindowPtrOfMainWin\>/checkAndGetMainWinIfMainWin/g' `grep '\<checkAndGetMainWindowPtrOfMainWin\>' -rl include/ src/`
# sed -i 's/\<checkAndGetMainWindowPtrOfControl\>/checkAndGetMainWinIfWindow/g' `grep '\<checkAndGetMainWindowPtrOfControl\>' -rl include/ src/`
sed -i 's/\<mg_GetMsgQueueForThisThread\>/getMsgQueueForThisThread/g' `grep '\<mg_GetMsgQueueForThisThread\>' -rl include/ src/`
exit 0

View File

@@ -1105,32 +1105,6 @@ static void unlock_zorder_info (void)
pthread_mutex_unlock (&pWin->pGCRInfo->lock);
}
}
#if 0 /* deprecated code */
static int fixed_slots [] = { ZNIDX_SCREENLOCK, ZNIDX_DOCKER,
ZNIDX_LAUNCHER };
/* Since 5.0.0 */
for (slot = 0; slot < TABLESIZE(fixed_slots); slot++) {
pWin = (PMAINWIN)(nodes[fixed_slots[slot]].hwnd);
if (pWin)
pthread_mutex_unlock (&pWin->pGCRInfo->lock);
}
slot = __mg_zorder_info->first_topmost;
for (; slot > 0; slot = nodes[slot].next) {
pWin = (PMAINWIN)(nodes[slot].hwnd);
if (pWin)
pthread_mutex_unlock (&pWin->pGCRInfo->lock);
}
slot = __mg_zorder_info->first_normal;
for (; slot > 0; slot = nodes[slot].next) {
pWin = (PMAINWIN)(nodes[slot].hwnd);
if (pWin)
pthread_mutex_unlock (&pWin->pGCRInfo->lock);
}
#endif /* deprecated code */
}
#endif /* define _MGRM_THREADS */
@@ -1612,136 +1586,6 @@ static void dskUpdateDesktopMenu (HMENU hDesktopMenu)
}
}
#if 0 /* deprecated code */
/* Since 5.0.0 */
slot = ZNIDX_SCREENLOCK;
if ((pWin = (PMAINWIN)(nodes[slot].hwnd)) &&
pWin->WinType == TYPE_MAINWIN) {
if (pWin->dwStyle & WS_VISIBLE)
mii.state = MFS_ENABLED;
else
mii.state = MFS_DISABLED;
mii.id = id;
mii.typedata = (DWORD)pWin->spCaption;
mii.itemdata = (DWORD)pWin;
InsertMenuItem(hWinMenu, iPos, TRUE, &mii);
id++;
iPos++;
}
/* Since 5.0.0 */
slot = ZNIDX_DOCKER;
if ((pWin = (PMAINWIN)(nodes[slot].hwnd)) &&
pWin->WinType == TYPE_MAINWIN) {
if (pWin->dwStyle & WS_VISIBLE)
mii.state = MFS_ENABLED;
else
mii.state = MFS_DISABLED;
mii.id = id;
mii.typedata = (DWORD)pWin->spCaption;
mii.itemdata = (DWORD)pWin;
InsertMenuItem(hWinMenu, iPos, TRUE, &mii);
id++;
iPos++;
}
if (iPos != 0) {
mii.type = MFT_SEPARATOR;
mii.state = 0;
mii.id = 0;
mii.typedata = 0;
InsertMenuItem(hWinMenu, iPos, TRUE, &mii);
iPos ++;
mii.type = MFT_STRING;
}
slot = __mg_zorder_info->first_topmost;
for (; slot > 0; slot = nodes[slot].next) {
pWin = (PMAINWIN)(nodes[slot].hwnd);
if (pWin && pWin->WinType == TYPE_MAINWIN &&
!(nodes[slot].flags & ZOF_IF_ALWAYSTOP)) {
if (pWin->dwStyle & WS_VISIBLE)
mii.state = MFS_ENABLED;
else
mii.state = MFS_DISABLED;
}
else {
continue;
}
mii.id = id;
mii.typedata = (DWORD)pWin->spCaption;
mii.itemdata = (DWORD)pWin;
InsertMenuItem(hWinMenu, iPos, TRUE, &mii);
id++;
iPos++;
}
if (iPos != 0) {
mii.type = MFT_SEPARATOR;
mii.state = 0;
mii.id = 0;
mii.typedata = 0;
InsertMenuItem(hWinMenu, iPos, TRUE, &mii);
iPos ++;
mii.type = MFT_STRING;
}
slot = __mg_zorder_info->first_normal;
for (; slot > 0; slot = nodes[slot].next) {
pWin = (PMAINWIN)(nodes[slot].hwnd);
if (pWin && pWin->WinType == TYPE_MAINWIN) {
if (pWin->dwStyle & WS_VISIBLE)
mii.state = MFS_ENABLED;
else
mii.state = MFS_DISABLED;
}
else {
continue;
}
mii.id = id;
mii.typedata = (DWORD)pWin->spCaption;
mii.itemdata = (DWORD)pWin;
InsertMenuItem(hWinMenu, iPos, TRUE, &mii);
id++;
iPos++;
}
/* Since 5.0.0 */
slot = ZNIDX_LAUNCHER;
if ((pWin = (PMAINWIN)(nodes[slot].hwnd)) &&
pWin->WinType == TYPE_MAINWIN) {
mii.type = MFT_SEPARATOR;
mii.state = 0;
mii.id = 0;
mii.typedata = 0;
InsertMenuItem(hWinMenu, iPos, TRUE, &mii);
iPos ++;
mii.type = MFT_STRING;
if (pWin->dwStyle & WS_VISIBLE)
mii.state = MFS_ENABLED;
else
mii.state = MFS_DISABLED;
mii.id = id;
mii.typedata = (DWORD)pWin->spCaption;
mii.itemdata = (DWORD)pWin;
InsertMenuItem(hWinMenu, iPos, TRUE, &mii);
id++;
iPos++;
}
#endif /* deprecated code */
nCount = GetMenuItemCount (hDesktopMenu);
for (iPos = nCount; iPos > 5; iPos --)
DeleteMenu (hDesktopMenu, iPos - 1, MF_BYPOSITION);
@@ -1750,77 +1594,36 @@ static void dskUpdateDesktopMenu (HMENU hDesktopMenu)
}
#endif
static int dskDesktopCommand (HMENU hDesktopMenu, int id)
static void close_all_main_window (void)
{
int level, slot;
PMAINWIN pWin;
ZORDERNODE* nodes = GET_ZORDERNODE(__mg_zorder_info);
for (level = 0; level < NR_ZORDER_LEVELS; level++) {
slot = __mg_zorder_info->first_in_levels[level];
for (; slot > 0; slot = nodes[slot].next) {
pWin = (PMAINWIN)(nodes[slot].hwnd);
if (pWin && (pWin->WinType == TYPE_MAINWIN))
SendNotifyMessage ((HWND)pWin, MSG_CLOSE, 0, 0);
}
}
}
static int dskDesktopCommand (HMENU hDesktopMenu, int id)
{
if (id == IDM_REDRAWBG)
SendMessage (HWND_DESKTOP, MSG_ERASEDESKTOP, 0, 0);
else if (id == IDM_CLOSEALLWIN) {
PMAINWIN pWin;
for (level = 0; level < NR_ZORDER_LEVELS; level++) {
slot = __mg_zorder_info->first_in_levels[level];
for (; slot > 0; slot = nodes[slot].next) {
pWin = (PMAINWIN)(nodes[slot].hwnd);
if (pWin && (pWin->WinType == TYPE_MAINWIN)
#ifndef _MGRM_THREADS
&& (pWin->pHosting == __mg_dsk_win)
#else
&& (pWin->pHosting == NULL)
#endif
)
SendNotifyMessage ((HWND)pWin, MSG_CLOSE, 0, 0);
}
}
#if 0 /* deprecated code */
static int fixed_slots [] = { ZNIDX_SCREENLOCK, ZNIDX_DOCKER,
ZNIDX_LAUNCHER };
/* Since 5.0.0 */
for (slot = 0; slot < TABLESIZE(fixed_slots); slot++) {
pWin = (PMAINWIN)(nodes[fixed_slots[slot]].hwnd);
if (pWin && (pWin->WinType != TYPE_CONTROL)
#ifndef _MGRM_THREADS
&& (pWin->pHosting == __mg_dsk_win)
#else
&& (pWin->pHosting == NULL)
#endif
)
PostMessage ((HWND)pWin, MSG_CLOSE, 0, 0);
}
slot = __mg_zorder_info->first_topmost;
for (; slot > 0; slot = nodes[slot].next) {
pWin = (PMAINWIN)(nodes[slot].hwnd);
if (pWin && (pWin->WinType != TYPE_CONTROL)
#ifndef _MGRM_THREADS
&& (pWin->pHosting == __mg_dsk_win)
#else
&& (pWin->pHosting == NULL)
#endif
)
PostMessage ((HWND)pWin, MSG_CLOSE, 0, 0);
}
slot = __mg_zorder_info->first_normal;
for (; slot > 0; slot = nodes[slot].next) {
pWin = (PMAINWIN)(nodes[slot].hwnd);
if (pWin && (pWin->WinType == TYPE_MAINWIN)
#ifndef _MGRM_THREADS
&& (pWin->pHosting == __mg_dsk_win)
#else
&& (pWin->pHosting == NULL)
#endif
)
PostMessage ((HWND)pWin, MSG_CLOSE, 0, 0);
}
#endif /* deprecated code */
close_all_main_window ();
}
else if (id == IDM_ENDSESSION) {
#ifdef _MGHAVE_VIRTUAL_WINDOW
//close_all_main_window ();
post_quit_to_all_message_threads (TRUE);
#else
SendNotifyMessage (HWND_DESKTOP, MSG_ENDSESSION, 0, 0);
#endif /* defined _MGHAVE_VIRTUAL_WINDOW */
}
#ifdef _MGHAVE_MENU
else if (id >= IDM_FIRSTWINDOW) {
@@ -2221,10 +2024,6 @@ static LRESULT DesktopWinProc (HWND hWnd, UINT message,
case MSG_ENDSESSION:
__mg_screensaver_destroy ();
#ifdef _MGHAVE_VIRTUAL_WINDOW
post_quit_to_all_message_threads ();
#endif /* defined _MGHAVE_VIRTUAL_WINDOW */
if (hDesktopDC)
ReleaseDC (hDesktopDC);
hDesktopDC = 0;

View File

@@ -4247,6 +4247,7 @@ int __mg_join_all_message_threads (void)
int nr = 0;
struct list_head *l, *tmp;
void* res;
pthread_t th = pthread_self();
list_for_each (l, &msg_queue_list) {
MSGQUEUE *msg_queue = (MSGQUEUE*)l;
@@ -4256,6 +4257,9 @@ int __mg_join_all_message_threads (void)
list_for_each_safe (l, tmp, &msg_queue_list) {
MSGQUEUE *msg_queue = (MSGQUEUE*)l;
if (th == msg_queue->th) {
continue;
}
pthread_join (msg_queue->th, &res);
if (res == PTHREAD_CANCELED) {
list_del (&msg_queue->list);
@@ -4268,14 +4272,19 @@ int __mg_join_all_message_threads (void)
return nr;
}
static inline int post_quit_to_all_message_threads (void)
static inline int post_quit_to_all_message_threads (BOOL no_self)
{
int nr = 0;
struct list_head *l;
pthread_t th = pthread_self();
list_for_each (l, &msg_queue_list) {
MSGQUEUE *msg_queue = (MSGQUEUE*)l;
dump_message_queue (msg_queue, __func__);
if (no_self && th == msg_queue->th) {
continue;
}
msg_queue->dwState |= QS_QUIT;
POST_MSGQ (msg_queue);
nr++;

View File

@@ -283,11 +283,6 @@ static inline void deleteThreadInfoKey (void)
{
pthread_key_delete (__mg_threadinfo_key);
}
MSGQUEUE* mg_GetMsgQueueForThisThread (void)
{
return (MSGQUEUE*) pthread_getspecific (__mg_threadinfo_key);
}
*/
/************************** System Initialization ****************************/
@@ -624,7 +619,6 @@ void GUIAPI TerminateGUI (int not_used)
/* Since 5.0.0 */
SendNotifyMessage (HWND_DESKTOP, MSG_ENDSESSION, 0, 0);
__mg_join_all_message_threads ();
pthread_join (__mg_dsk_msg_queue->th, NULL);
/* Tell event parsor quit */