about summary refs log tree commit diff stats
path: root/main.lua
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2022-06-07 14:11:09 -0700
committerKartik K. Agaram <vc@akkartik.com>2022-06-07 14:11:09 -0700
commitff08bbe7f4e9b84291c72fc77e1e7daa163fdff4 (patch)
treeb043ace432bd20b3d7aa1eb0d592245848055a68 /main.lua
parent6b628781d161bcfc2d5690ef77758379358a272e (diff)
downloadtext.love-ff08bbe7f4e9b84291c72fc77e1e7daa163fdff4.tar.gz
first commandline arg: window dimensions
Hopefully there won't be too many others.
Diffstat (limited to 'main.lua')
-rw-r--r--main.lua41
1 files changed, 33 insertions, 8 deletions
diff --git a/main.lua b/main.lua
index c7062c8..13d4efe 100644
--- a/main.lua
+++ b/main.lua
@@ -85,7 +85,13 @@ function App.initialize(arg)
   love.keyboard.setTextInput(true)  -- bring up keyboard on touch screen
   love.keyboard.setKeyRepeat(true)
 
-  initialize_window_geometry()
+  if arg[1] == '-geometry' then
+    initialize_window_geometry(arg[2])
+    table.remove(arg, 2)
+    table.remove(arg, 1)
+  else
+    initialize_window_geometry()
+  end
 
   initialize_font_settings(20)
 
@@ -106,19 +112,38 @@ function App.initialize(arg)
   end
 end  -- App.initialize
 
-function initialize_window_geometry()
-  -- maximize window
-  love.window.setMode(0, 0)  -- maximize
-  App.screen.width, App.screen.height, App.screen.flags = love.window.getMode()
-  -- shrink slightly to account for window decoration
-  App.screen.width = App.screen.width-100
-  App.screen.height = App.screen.height-100
+function initialize_window_geometry(geometry_spec)
+  local geometry_initialized
+  if geometry_spec then
+    geometry_initialized = parse_geometry_spec(geometry_spec)
+  end
+  if not geometry_initialized then
+    -- maximize window
+    love.window.setMode(0, 0)  -- maximize
+    App.screen.width, App.screen.height, App.screen.flags = love.window.getMode()
+    -- shrink slightly to account for window decoration
+    App.screen.width = App.screen.width-100
+    App.screen.height = App.screen.height-100
+  end
   App.screen.flags.resizable = true
   App.screen.flags.minwidth = math.min(App.screen.width, 200)
   App.screen.flags.minheight = math.min(App.screen.width, 200)
   love.window.updateMode(App.screen.width, App.screen.height, App.screen.flags)
 end
 
+function parse_geometry_spec(geometry_spec)
+  local width, height, x, y = geometry_spec:match('(%d+)x(%d+)%+(%d+)%+(%d+)')
+  if width == nil then
+    print('invalid geometry spec: '..geometry_spec)
+    print('expected format: {width}x{height}+{x}+{y}')
+    return false
+  end
+  App.screen.width = math.floor(tonumber(width))
+  App.screen.height = math.floor(tonumber(height))
+  App.screen.flags = {x=math.floor(tonumber(x)), y=math.floor(tonumber(y))}
+  return true
+end
+
 function love.resize(w, h)
 --?   print(("Window resized to width: %d and height: %d."):format(w, h))
   App.screen.width, App.screen.height = w, h