From d5b40bbd4ddd3fe4b245ad598c1a35a12abcb008 Mon Sep 17 00:00:00 2001
From: Emmanuel Anne <emmanuel.anne@gmail.com>
Date: Sun, 29 Jul 2012 23:40:07 +0200
Subject: [PATCH] geometry command line argument

---
 FoFiX.py      |   17 ++++++++++++++++-
 GameEngine.py |    5 +++++
 2 files changed, 21 insertions(+), 1 deletion(-)
 mode change 100644 => 100755 FoFiX.py

diff --git a/FoFiX.py b/FoFiX.py
old mode 100644
new mode 100755
index e9d310c..b3de75b
--- a/FoFiX.py
+++ b/FoFiX.py
@@ -43,6 +43,7 @@ import getopt
 import sys
 import os
 import Version
+import re
 
 ## Display command-line usage and exit.
 # Outputs to stdout unless py2exe'd, in which case the usage is presented
@@ -58,6 +59,7 @@ Options:
                                       your platform.  Use "reset" to use the
                                       usual fofix.ini but clear it first.
   --fullscreen=, -f [true/false]      Force (non-)usage of full-screen mode.
+  --geometry=,   -g [resolution][+x][+y] like Xorg standard argument
   --resolution=, -r [resolution]      Force a specific resolution to be used.
   --theme=,  -t [theme]               Force the specified theme to be used.
                                       Remember to quote the theme name if it
@@ -89,7 +91,7 @@ One-shot mode options (ignored unless in one-shot mode):
   sys.exit(1)
 
 try:
-  opts, args = getopt.getopt(sys.argv[1:], "hvdc:f:r:t:s:l:p:m:n:", ["help", "verbose", "debug", "config=", "fullscreen=", "resolution=", "theme=", "song=", "diff=", "part=", "mode=", "nbrplayers=", "opengl-error-checking"])
+	opts, args = getopt.getopt(sys.argv[1:], "hvdc:f:g:r:t:s:l:p:m:n:", ["help", "verbose", "debug", "config=", "fullscreen=", "geometry=", "resolution=", "theme=", "song=", "diff=", "part=", "mode=", "nbrplayers=", "opengl-error-checking"])
 except getopt.GetoptError, e:
   _usage(str(e))  # str(e): error message from getopt, e.g. "option --some-invalid-option not recognized"
 if ('-h', '') in opts or ('--help', '') in opts:
@@ -118,6 +120,8 @@ def main():
   configFile = None
   fullscreen = None
   resolution = None
+  x = None
+  y = None
   theme = None
   debug = False
   difficulty = None
@@ -135,6 +139,11 @@ def main():
       fullscreen = arg
     if opt in ["--resolution", "-r"]:
       resolution = arg
+    if opt in ["--geometry", "-g"]:
+      r = re.match('([0-9]+x\d+)\+?(\d+)?\+?(\d+)?',arg)
+      print "geometry tested ",arg
+      (resolution,x,y) = r.groups()
+      print "found ",resolution," x ",x," y ",y
     if opt in ["--theme", "-t"]:
       theme = arg
     if opt in ["--song", "-s"]:
@@ -167,6 +176,12 @@ def main():
   #Lysdestic - Change resolution from CLI
   if resolution is not None:
     Config.set("video", "resolution", resolution)
+  if x is not None:
+    Config.set("video", "x", x)
+    Config.set("video","fullscreen",False)
+  if y is not None:
+    Config.set("video", "y", y)
+    Config.set("video","fullscreen",False)
 
   #Lysdestic - Alter theme from CLI
   if theme is not None:
diff --git a/GameEngine.py b/GameEngine.py
index 12ef63d..4e9ec60 100644
--- a/GameEngine.py
+++ b/GameEngine.py
@@ -93,6 +93,8 @@ Config.define("video",  "fullscreen",   bool,  False,  text = _("Fullscreen Mode
 Config.define("video",  "multisamples", int,   4,     text = _("Antialiasing Quality"), options = {0: _("None"), 2: "2x", 4: "4x", 6: "6x", 8: "8x"}, tipText = _("Sets the antialiasing quality of openGL rendering. Higher values reduce jaggediness, but could affect performance. (This is affected by the 'Performance' quickset)"))
 Config.define("video",  "disable_fretsfx", bool, False, text = _("Show Fret Glow Effect"), options = {False: _("Yes"), True: _("No")}, tipText = _("Turn on or off the glow that appears around a fret when you press it."))
 Config.define("video",  "resolution",   str,   "640x480")
+Config.define("video",  "x",   int,   0)
+Config.define("video",  "y",   int,   0)
 Config.define("video",  "fps",          int,   80,    text = _("Frames per Second"), options = dict([(n, n) for n in range(1, 120)]), tipText = _("Set the number of frames to render per second. Higher values are better, but your computer may not be able to keep up. You probably can leave this alone. (This is affected by the 'Performance' quickset)"))
 Config.define("video",  "show_fps",     bool,   False,  text = _("Print Frames per Second"), options = {False: _("No"), True: _("Yes")}, tipText = _("This will display your FPS on some screens, and if running from sources will print your FPS there every two seconds."))
 Config.define("video",  "hitglow_color", int,  0,     text = _("Fret Glow Color"), options = {0: _("Same as Fret"), 1: _("Actual Color")}, tipText = _("Sets whether or not the fret glow image will be color-masked with the theme-determined fret color."))
@@ -545,6 +547,9 @@ class GameEngine(Engine):
     os.environ['SDL_VIDEO_WINDOW_POS'] = 'center'
 
     width, height = [int(s) for s in self.config.get("video", "resolution").split("x")]
+    self.x = Config.get("video","x")
+    self.y = Config.get("video","y")
+    os.environ['SDL_VIDEO_WINDOW_POS'] = str(self.x)+","+str(self.y)
     fullscreen    = self.config.get("video", "fullscreen")
     multisamples  = self.config.get("video", "multisamples")
     self.video.setMode((width, height), fullscreen = fullscreen, multisamples = multisamples)
-- 
1.7.10

