From f6765518500be89c1b3cc7371be3d2d3010e85d7 Mon Sep 17 00:00:00 2001
From: Cloudef <mailRoxas@gmail.com>
Date: Mon, 29 Aug 2011 22:58:45 +0300
Subject: [PATCH] fakedisp_driver

---
 dlls/winex11.drv/Makefile.in   |    3 +-
 dlls/winex11.drv/fakedisp.c    |   69 ++++++++++++++++++++++++++++++++++++++++
 dlls/winex11.drv/fakedisp.h    |   29 +++++++++++++++++
 dlls/winex11.drv/x11drv.h      |    4 ++
 dlls/winex11.drv/x11drv_main.c |   18 ++++++++++
 5 files changed, 122 insertions(+), 1 deletions(-)
 create mode 100644 dlls/winex11.drv/fakedisp.c
 create mode 100644 dlls/winex11.drv/fakedisp.h

diff --git a/dlls/winex11.drv/Makefile.in b/dlls/winex11.drv/Makefile.in
index 9af183c..01158ef 100644
--- a/dlls/winex11.drv/Makefile.in
+++ b/dlls/winex11.drv/Makefile.in
@@ -37,7 +37,8 @@ C_SRCS = \
 	xinerama.c \
 	xrandr.c \
 	xrender.c \
-	xvidmode.c
+	xvidmode.c \
+	fakedisp.c

 RC_SRCS = version.rc

diff --git a/dlls/winex11.drv/fakedisp.c b/dlls/winex11.drv/fakedisp.c
new file mode 100644
index 0000000..05423a8
--- /dev/null
+++ b/dlls/winex11.drv/fakedisp.c
@@ -0,0 +1,69 @@
+/*
+ * Wine X11drv fakedisp interface
+ *
+ * Copyright 2003 Jari Vetoniemi
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include "config.h"
+#include "wine/port.h"
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "x11drv.h"
+#include "fakedisp.h"
+
+extern int usefakedisp;
+extern int fakedispwidth;
+extern int fakedispheight;
+extern int fakedispfreq;
+
+static int X11DRV_FakeDisp_GetCurrentMode(void)
+{
+    return 0;
+}
+
+static LONG X11DRV_FakeDisp_SetCurrentMode(int mode)
+{
+   return DISP_CHANGE_SUCCESSFUL;
+}
+
+void X11DRV_FakeDisp_Init(void)
+{
+    char *fakedisp_env;
+    int width, height, freq, c;
+    if (!usefakedisp) return; /* disabled in config */
+    fakedisp_env = getenv( "WINE_FAKEDISP" );
+    if(fakedisp_env != NULL)
+    {
+        c = sscanf(fakedisp_env, "%dx%d_%d", &width, &height, &freq);
+        if(c)
+           fakedispwidth  = width;
+        if(c>1)
+           fakedispheight = height;
+        if(c>2)
+           fakedispfreq   = freq;
+    }
+
+    X11DRV_Settings_SetHandlers("FakeDisp",
+                                X11DRV_FakeDisp_GetCurrentMode,
+                                X11DRV_FakeDisp_SetCurrentMode,
+                                1, 1);
+    X11DRV_Settings_AddOneMode(fakedispwidth, fakedispheight, 0, fakedispfreq);
+    X11DRV_Settings_AddDepthModes();
+}
+
diff --git a/dlls/winex11.drv/fakedisp.h b/dlls/winex11.drv/fakedisp.h
new file mode 100644
index 0000000..beccd11
--- /dev/null
+++ b/dlls/winex11.drv/fakedisp.h
@@ -0,0 +1,29 @@
+/*
+ * Wine X11drv fakedisp interface
+ *
+ * Copyright 2011 Jari Vetoniemi
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+#ifndef __WINE_FAKEDISP_H
+#define __WINE_FAKEDISP_H
+
+#ifndef __WINE_CONFIG_H
+# error You must include config.h to use this header
+#endif
+
+void X11DRV_FakeDisp_Init(void) DECLSPEC_HIDDEN;
+
+#endif /* __WINE_FAKEDISP_H */
diff --git a/dlls/winex11.drv/x11drv.h b/dlls/winex11.drv/x11drv.h
index 260c0a4..ac870df 100644
--- a/dlls/winex11.drv/x11drv.h
+++ b/dlls/winex11.drv/x11drv.h
@@ -617,6 +617,10 @@ extern unsigned int text_caps DECLSPEC_HIDDEN;
 extern int use_xkb DECLSPEC_HIDDEN;
 extern int usexrandr DECLSPEC_HIDDEN;
 extern int usexvidmode DECLSPEC_HIDDEN;
+extern int usefakedisp DECLSPEC_HIDDEN;
+extern int fakedispwidth DECLSPEC_HIDDEN;
+extern int fakedispheight DECLSPEC_HIDDEN;
+extern int fakedispfreq DECLSPEC_HIDDEN;
 extern BOOL ximInComposeMode DECLSPEC_HIDDEN;
 extern int use_take_focus DECLSPEC_HIDDEN;
 extern int use_primary_selection DECLSPEC_HIDDEN;
diff --git a/dlls/winex11.drv/x11drv_main.c b/dlls/winex11.drv/x11drv_main.c
index 8e2082d..654a686 100644
--- a/dlls/winex11.drv/x11drv_main.c
+++ b/dlls/winex11.drv/x11drv_main.c
@@ -78,6 +78,10 @@ RECT virtual_screen_rect;
 Window root_window;
 int usexvidmode = 1;
 int usexrandr = 1;
+int usefakedisp = 0;
+int fakedispwidth = 800;
+int fakedispheight = 600;
+int fakedispfreq = 60;
 int usexcomposite = 1;
 int use_xkb = 1;
 int use_take_focus = 1;
@@ -401,6 +405,18 @@ static void setup_options(void)
     if (!get_config_key( hkey, appkey, "UseXRandR", buffer, sizeof(buffer) ))
         usexrandr = IS_OPTION_TRUE( buffer[0] );

+    if (!get_config_key( hkey, appkey, "UseFakeDisp", buffer, sizeof(buffer) ))
+        usefakedisp = IS_OPTION_TRUE( buffer[0] );
+
+    if (!get_config_key( hkey, appkey, "FakeDispWidth", buffer, sizeof(buffer) ))
+        fakedispwidth = atoi(buffer);
+
+    if (!get_config_key( hkey, appkey, "FakeDispHeight", buffer, sizeof(buffer) ))
+        fakedispheight = atoi(buffer);
+
+    if (!get_config_key( hkey, appkey, "FakeDispFreq", buffer, sizeof(buffer) ))
+        fakedispfreq = atoi(buffer);
+
     if (!get_config_key( hkey, appkey, "UseTakeFocus", buffer, sizeof(buffer) ))
         use_take_focus = IS_OPTION_TRUE( buffer[0] );

@@ -578,6 +594,8 @@ static BOOL process_attach(void)
     xinerama_init( WidthOfScreen(screen), HeightOfScreen(screen) );
     X11DRV_Settings_Init();

+    /* initialize FakeDisp */
+    X11DRV_FakeDisp_Init();
 #ifdef SONAME_LIBXXF86VM
     /* initialize XVidMode */
     X11DRV_XF86VM_Init();
--
1.7.6.1

