Eric Pouech wrote: 

>to exchange information 
>between wineconsole and kernel is not the right thing to do the correct way is 
>to:
>- enhance the wine server protocol to grab max win size in kernel32 
>from wine server

I've been able to achieve this.

/***********************************************************************
 *            GetLargestConsoleWindowSize_helper
 */
COORD GetLargestConsoleWindowSize_helper(HANDLE hConsoleOutput)
{
    int screen_width = 0, screen_height = 0;
    COORD fontsize, max_console;

    SERVER_START_REQ( get_desktop_workarea )
    {
        if(!wine_server_call_err( req ))
        {
            screen_width = reply->screen_x;
            screen_height = reply->screen_y;
        }
    }
    SERVER_END_REQ;

    fontsize = GetConsoleFontSize(hConsoleOutput, 0);

    max_console.X = (screen_width / fontsize.X) - 6;
    max_console.Y = (screen_height / fontsize.Y) - 5;

    if (max_console.X < 0 || max_console.Y < 0)
    {
        max_console.X = 80;
        max_console.Y = 25;
    }
    return max_console;
}

>- enhance wineconsole to set the max wine size into wine server

I'm not really sure how to do this.  I thought this code might work in 
programs/wineconsole/wineconsole.c:

RECT workarea;
/* Send desktop workarea to server */
SystemParametersInfoA(SPI_GETWORKAREA, 0, &workarea, 0);
    
SERVER_START_REQ( get_desktop_workarea )
{
    if(!wine_server_call_err( req ))
    {
        req->spi_workarea = workarea;
    }
}
SERVER_END_REQ;

Unfortunately, while Wine compiles perfectly with the other changes to the 
server (see attached files), no proper values are returned (only zero).
By setting hardcoded constants in server/window.c, I have tested 
GetLargestConsoleWindowSize, where all functions work as expected.

Any advice on sending data to the server would be appreciated.
--- dlls/kernel32/console.c.orig        2013-03-30 05:19:16.000000000 +1100
+++ dlls/kernel32/console.c     2013-04-10 21:56:21.071967727 +1000
@@ -1364,6 +1364,37 @@
 
 
 /***********************************************************************
+ *            GetLargestConsoleWindowSize_helper
+ */
+COORD GetLargestConsoleWindowSize_helper(HANDLE hConsoleOutput)
+{
+    int screen_width = 0, screen_height = 0;
+    COORD fontsize, max_console;
+
+    SERVER_START_REQ( get_desktop_workarea )
+    {
+        if(!wine_server_call_err( req ))
+        {
+            screen_width = reply->screen_x;
+            screen_height = reply->screen_y;
+        }
+    }
+    SERVER_END_REQ;
+
+    fontsize = GetConsoleFontSize(hConsoleOutput, 0);
+
+    max_console.X = (screen_width / fontsize.X) - 6;
+    max_console.Y = (screen_height / fontsize.Y) - 5;
+
+    if (max_console.X < 0 || max_console.Y < 0)
+    {
+        max_console.X = 80;
+        max_console.Y = 25;
+    }
+    return max_console;
+}
+
+/***********************************************************************
  *            GetLargestConsoleWindowSize   (KERNEL32.@)
  *
  * NOTE
@@ -1380,8 +1411,7 @@
        COORD c;
        DWORD w;
     } x;
-    x.c.X = 80;
-    x.c.Y = 24;
+    x.c = GetLargestConsoleWindowSize_helper(hConsoleOutput);
     TRACE("(%p), returning %dx%d (%x)\n", hConsoleOutput, x.c.X, x.c.Y, x.w);
     return x.w;
 }
@@ -1401,8 +1431,7 @@
 COORD WINAPI GetLargestConsoleWindowSize(HANDLE hConsoleOutput)
 {
     COORD c;
-    c.X = 80;
-    c.Y = 24;
+    c = GetLargestConsoleWindowSize_helper(hConsoleOutput);
     TRACE("(%p), returning %dx%d\n", hConsoleOutput, c.X, c.Y);
     return c;
 }
@@ -3236,28 +3265,77 @@
 #undef GetConsoleFontSize
 DWORD WINAPI GetConsoleFontSize(HANDLE hConsole, DWORD font)
 {
+    int col = 0, lin = 0, colpix = 0, linpix = 0;
+    HWND hWnd;
+
     union {
         COORD c;
         DWORD w;
     } x;
 
-    FIXME(": (%p, %d) stub!\n", hConsole, font);
-    SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
+    SERVER_START_REQ( get_console_output_info )
+    {
+        req->handle = console_handle_unmap(hConsole);
+        if (!wine_server_call_err( req ))
+        {
+            col = (reply->win_right - reply->win_left) + 1;
+            lin = (reply->win_bottom - reply->win_top) + 1;
+        }
+    }
+    SERVER_END_REQ;
+
+    hWnd = GetConsoleWindow();
 
-    x.c.X = 0;
-    x.c.Y = 0;
+    SERVER_START_REQ( get_window_rectangles )
+    {
+        req->handle = hWnd;
+        if (!wine_server_call_err( req ))
+        {
+            colpix = reply->client.right - reply->client.left;
+            linpix = reply->client.bottom - reply->client.top;
+        }
+    }
+    SERVER_END_REQ;
+
+    x.c.X = colpix / col;
+    x.c.Y = linpix / lin;
     return x.w;
 }
 #endif /* defined(__i386__) */
 
-
 #ifndef __i386__
 COORD WINAPI GetConsoleFontSize(HANDLE hConsole, DWORD font)
 {
+    int col = 0, lin = 0, colpix = 0, linpix = 0;
+    HWND hWnd;
     COORD c;
-    c.X = 80;
-    c.Y = 24;
-     FIXME(": (%p, %d) stub!\n", hConsole, font);
+
+    SERVER_START_REQ( get_console_output_info )
+    {
+        req->handle = console_handle_unmap(hConsole);
+        if (!wine_server_call_err( req ))
+        {
+            col = (reply->win_right - reply->win_left) + 1;
+            lin = (reply->win_bottom - reply->win_top) + 1;
+        }
+    }
+    SERVER_END_REQ;
+
+    hWnd = GetConsoleWindow();
+
+    SERVER_START_REQ( get_window_rectangles )
+    {
+        req->handle = hWnd;
+        if (!wine_server_call_err( req ))
+        {
+            colpix = reply->client.right - reply->client.left;
+            linpix = reply->client.bottom - reply->client.top;
+        }
+    }
+    SERVER_END_REQ;
+
+    c.X = colpix / col;
+    c.Y = linpix / lin;
     return c;
 }
 #endif /* defined(__i386__) */
--- server/protocol.def.orig    2013-03-30 05:19:16.000000000 +1100
+++ server/protocol.def 2013-04-10 21:23:14.484942507 +1000
@@ -2279,6 +2279,15 @@
 @END
 
 
+/* Retrieve the desktop workarea */
+@REQ(get_desktop_workarea)
+    RECT  spi_workarea;         /* values from SystemParametersInfo */
+@REPLY
+    int   screen_x;             /* screen dimensions without taskbar */
+    int   screen_y;
+@END
+
+
 /* Set a window owner */
 @REQ(set_window_owner)
     user_handle_t  handle;      /* handle to the window */
--- include/wine/server_protocol.h.orig 2013-03-30 05:19:16.000000000 +1100
+++ include/wine/server_protocol.h      2013-04-10 21:15:30.190779476 +1000
@@ -3152,6 +3152,20 @@
 
 
 
+struct get_desktop_workarea_request
+{
+    struct request_header __header;
+    RECT  spi_workarea;
+};
+struct get_desktop_workarea_reply
+{
+    struct reply_header __header;
+    int          screen_x;
+    int          screen_y;
+};
+
+
+
 struct set_window_owner_request
 {
     struct request_header __header;
@@ -5098,6 +5112,7 @@
     REQ_create_window,
     REQ_destroy_window,
     REQ_get_desktop_window,
+    REQ_get_desktop_workarea,
     REQ_set_window_owner,
     REQ_get_window_info,
     REQ_set_window_info,
@@ -5354,6 +5369,7 @@
     struct create_window_request create_window_request;
     struct destroy_window_request destroy_window_request;
     struct get_desktop_window_request get_desktop_window_request;
+    struct get_desktop_workarea_request get_desktop_workarea_request;
     struct set_window_owner_request set_window_owner_request;
     struct get_window_info_request get_window_info_request;
     struct set_window_info_request set_window_info_request;
@@ -5608,6 +5624,7 @@
     struct create_window_reply create_window_reply;
     struct destroy_window_reply destroy_window_reply;
     struct get_desktop_window_reply get_desktop_window_reply;
+    struct get_desktop_workarea_reply get_desktop_workarea_reply;
     struct set_window_owner_reply set_window_owner_reply;
     struct get_window_info_reply get_window_info_reply;
     struct set_window_info_reply set_window_info_reply;
--- server/window.c.orig        2013-03-30 05:19:16.000000000 +1100
+++ server/window.c     2013-04-10 21:25:15.295423714 +1000
@@ -1954,6 +1954,16 @@
 }
 
 
+/* retrieve the desktop workarea */
+DECL_HANDLER(get_desktop_workarea)
+{
+    int screen_w = req->spi_workarea.right;
+    int screen_h = req->spi_workarea.bottom;
+    reply->screen_x = screen_w;
+    reply->screen_y = screen_h;
+}
+
+
 /* set a window owner */
 DECL_HANDLER(set_window_owner)
 {
--- programs/wineconsole/wineconsole.c.orig     2013-03-30 05:19:16.000000000 
+1100
+++ programs/wineconsole/wineconsole.c  2013-04-10 21:16:57.261684846 +1000
@@ -576,6 +576,7 @@
     DWORD              ret;
     struct config_data  cfg;
     STARTUPINFOW        si;
+    RECT workarea;
 
     data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*data));
     if (!data) return 0;
@@ -592,6 +593,18 @@
     /* load settings */
     WINECON_RegLoad(appname, &cfg);
 
+    /* Send desktop workarea to server */
+    SystemParametersInfoA(SPI_GETWORKAREA, 0, &workarea, 0);
+    
+    SERVER_START_REQ( get_desktop_workarea )
+    {
+        if(!wine_server_call_err( req ))
+        {
+            req->spi_workarea = workarea;
+        }
+    }
+    SERVER_END_REQ;
+
     /* some overrides */
     if (pid == 0)
     {


Reply via email to