Author: hbelusca
Date: Sat Aug 15 17:05:13 2015
New Revision: 68716
URL:
http://svn.reactos.org/svn/reactos?rev=68716&view=rev
Log:
[CONSRV]
Change console processes priority when the console gains or loses focus. FIXME: Win2k3
backtraces show that we should call NtUserSetInformationProcess(unimplemented in ROS) to
set some win32 process foreground flags.
CORE-9911
Modified:
trunk/reactos/win32ss/user/winsrv/consrv/console.c
trunk/reactos/win32ss/user/winsrv/consrv/frontends/gui/conwnd.c
trunk/reactos/win32ss/user/winsrv/consrv/handle.c
trunk/reactos/win32ss/user/winsrv/consrv/include/conio_winsrv.h
Modified: trunk/reactos/win32ss/user/winsrv/consrv/console.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/win32ss/user/winsrv/consrv…
==============================================================================
--- trunk/reactos/win32ss/user/winsrv/consrv/console.c [iso-8859-1] (original)
+++ trunk/reactos/win32ss/user/winsrv/consrv/console.c [iso-8859-1] Sat Aug 15 17:05:13
2015
@@ -689,6 +689,7 @@
InitializeListHead(&Console->ProcessList);
Console->NotifiedLastCloseProcess = NULL;
Console->NotifyLastClose = FALSE;
+ Console->HasFocus = FALSE;
/* Initialize pausing support */
Console->PauseFlags = 0;
@@ -939,6 +940,46 @@
}
return Status;
+}
+
+VOID
+ConSrvSetProcessFocus(IN PCSR_PROCESS CsrProcess,
+ IN BOOLEAN SetForeground)
+{
+ // FIXME: Call NtUserSetInformationProcess (currently unimplemented!)
+ // for setting Win32 foreground/background flags.
+
+ if (SetForeground)
+ CsrSetForegroundPriority(CsrProcess);
+ else
+ CsrSetBackgroundPriority(CsrProcess);
+}
+
+NTSTATUS NTAPI
+ConSrvSetConsoleProcessFocus(IN PCONSRV_CONSOLE Console,
+ IN BOOLEAN SetForeground)
+{
+ PLIST_ENTRY current_entry;
+ PCONSOLE_PROCESS_DATA current;
+
+ /* If the console is already being destroyed, just return */
+ if (!ConDrvValidateConsoleState((PCONSOLE)Console, CONSOLE_RUNNING))
+ return STATUS_UNSUCCESSFUL;
+
+ /*
+ * Loop through the process list, from the most recent process
+ * to the oldest one, and for each, set its foreground priority.
+ */
+ current_entry = Console->ProcessList.Flink;
+ while (current_entry != &Console->ProcessList)
+ {
+ current = CONTAINING_RECORD(current_entry, CONSOLE_PROCESS_DATA, ConsoleLink);
+ current_entry = current_entry->Flink;
+
+ ConSrvSetProcessFocus(current->Process, SetForeground);
+ }
+
+ return STATUS_SUCCESS;
}
Modified: trunk/reactos/win32ss/user/winsrv/consrv/frontends/gui/conwnd.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/win32ss/user/winsrv/consrv…
==============================================================================
--- trunk/reactos/win32ss/user/winsrv/consrv/frontends/gui/conwnd.c [iso-8859-1]
(original)
+++ trunk/reactos/win32ss/user/winsrv/consrv/frontends/gui/conwnd.c [iso-8859-1] Sat Aug
15 17:05:13 2015
@@ -290,6 +290,7 @@
if (!ConDrvValidateConsoleUnsafe((PCONSOLE)Console, CONSOLE_RUNNING, TRUE)) return;
+ /* Send a menu event */
er.EventType = MENU_EVENT;
er.Event.MenuEvent.dwCommandId = CmdId;
ConioProcessInputEvent(Console, &er);
@@ -755,6 +756,16 @@
if (!ConDrvValidateConsoleUnsafe((PCONSOLE)Console, CONSOLE_RUNNING, TRUE)) return;
+ /* Set console focus state */
+ Console->HasFocus = SetFocus;
+
+ /*
+ * Set the priority of the processes of this console
+ * in accordance with the console focus state.
+ */
+ ConSrvSetConsoleProcessFocus(Console, SetFocus);
+
+ /* Send a focus event */
er.EventType = FOCUS_EVENT;
er.Event.FocusEvent.bSetFocus = SetFocus;
ConioProcessInputEvent(Console, &er);
@@ -1855,6 +1866,7 @@
if (lParam & 0x01000000)
dwControlKeyState |= ENHANCED_KEY;
+ /* Send a mouse event */
er.EventType = MOUSE_EVENT;
er.Event.MouseEvent.dwMousePosition = PointToCoord(GuiData, lParam);
er.Event.MouseEvent.dwButtonState = dwButtonState;
Modified: trunk/reactos/win32ss/user/winsrv/consrv/handle.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/win32ss/user/winsrv/consrv…
==============================================================================
--- trunk/reactos/win32ss/user/winsrv/consrv/handle.c [iso-8859-1] (original)
+++ trunk/reactos/win32ss/user/winsrv/consrv/handle.c [iso-8859-1] Sat Aug 15 17:05:13
2015
@@ -579,8 +579,12 @@
/* Return the console handle to the caller */
ConsoleInitInfo->ConsoleStartInfo->ConsoleHandle =
ProcessData->ConsoleHandle;
- /* Insert the process into the processes list of the console */
+ /*
+ * Insert the process into the processes list of the console,
+ * and set its foreground priority.
+ */
InsertHeadList(&Console->ProcessList, &ProcessData->ConsoleLink);
+ ConSrvSetProcessFocus(ProcessData->Process, Console->HasFocus);
/* Add a reference count because the process is tied to the console */
_InterlockedIncrement(&Console->ReferenceCount);
@@ -694,8 +698,12 @@
/* Return the console handle to the caller */
ConsoleStartInfo->ConsoleHandle = ProcessData->ConsoleHandle;
- /* Insert the process into the processes list of the console */
+ /*
+ * Insert the process into the processes list of the console,
+ * and set its foreground priority.
+ */
InsertHeadList(&Console->ProcessList, &ProcessData->ConsoleLink);
+ ConSrvSetProcessFocus(ProcessData->Process, Console->HasFocus);
/* Add a reference count because the process is tied to the console */
_InterlockedIncrement(&Console->ReferenceCount);
Modified: trunk/reactos/win32ss/user/winsrv/consrv/include/conio_winsrv.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/win32ss/user/winsrv/consrv…
==============================================================================
--- trunk/reactos/win32ss/user/winsrv/consrv/include/conio_winsrv.h [iso-8859-1]
(original)
+++ trunk/reactos/win32ss/user/winsrv/consrv/include/conio_winsrv.h [iso-8859-1] Sat Aug
15 17:05:13 2015
@@ -148,6 +148,7 @@
LIST_ENTRY ProcessList; /* List of processes owning the console. The first
one is the so-called "Console Leader Process" */
PCONSOLE_PROCESS_DATA NotifiedLastCloseProcess; /* Pointer to the unique process that
needs to be notified when the console leader process is killed */
BOOLEAN NotifyLastClose; /* TRUE if the console should send a control event
when the console leader process is killed */
+ BOOLEAN HasFocus; /* TRUE if the console has focus (is in the
foreground) */
/******************************* Pausing support ******************************/
BYTE PauseFlags;
@@ -206,6 +207,12 @@
ConSrvConsoleProcessCtrlEvent(IN PCONSRV_CONSOLE Console,
IN ULONG ProcessGroupId,
IN ULONG CtrlEvent);
+VOID
+ConSrvSetProcessFocus(IN PCSR_PROCESS CsrProcess,
+ IN BOOLEAN SetForeground);
+NTSTATUS NTAPI
+ConSrvSetConsoleProcessFocus(IN PCONSRV_CONSOLE Console,
+ IN BOOLEAN SetForeground);
/* coninput.c */
VOID NTAPI ConioProcessKey(PCONSRV_CONSOLE Console, MSG* msg);