Skip to content

Commit c58d737

Browse files
committed
Merge pull request OpenRA#5597 from Happy0/mouse_window_focus
Removing requirement to restart game after applying changes to mouse focus option
2 parents f115dda + 89c9499 commit c58d737

File tree

9 files changed

+56
-19
lines changed

9 files changed

+56
-19
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Also thanks to:
3535
* Fahrradkette
3636
* Frank Razenberg (zzattack)
3737
* Gareth Needham (Ripley`)
38+
* Gordon Martin (Happy0)
3839
* Igor Popov (ihptru)
3940
* Iran
4041
* James Dunne (jsd)

OpenRA.Game/Graphics/Renderer.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,5 +229,15 @@ public void DisableDepthBuffer()
229229
Flush();
230230
Device.DisableDepthBuffer();
231231
}
232+
233+
public void GrabWindowMouseFocus()
234+
{
235+
device.GrabWindowMouseFocus();
236+
}
237+
238+
public void ReleaseWindowMouseFocus()
239+
{
240+
device.ReleaseWindowMouseFocus();
241+
}
232242
}
233243
}

OpenRA.Game/IGraphicsDevice.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ public interface IGraphicsDevice : IDisposable
5858
void DisableDepthBuffer();
5959

6060
void SetBlendMode(BlendMode mode);
61+
62+
void GrabWindowMouseFocus();
63+
void ReleaseWindowMouseFocus();
6164
}
6265

6366
public interface IVertexBuffer<T>

OpenRA.Game/Settings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public class GameSettings
129129
public bool ShowShellmap = true;
130130

131131
public bool ViewportEdgeScroll = true;
132-
public bool LockMouseWindow = true;
132+
public bool LockMouseWindow = false;
133133
public MouseScrollType MouseScroll = MouseScrollType.Standard;
134134
public float ViewportEdgeScrollStep = 10f;
135135
public float UIScrollSpeed = 50f;

OpenRA.Mods.RA/Widgets/Logic/SettingsLogic.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,18 @@ Action InitInputPanel(Widget panel)
253253
BindSliderPref(panel, "SCROLLSPEED_SLIDER", gs, "ViewportEdgeScrollStep");
254254
BindSliderPref(panel, "UI_SCROLLSPEED_SLIDER", gs, "UIScrollSpeed");
255255

256+
// Apply mouse focus preferences immediately
257+
var lockMouseCheckbox = panel.Get<CheckboxWidget>("LOCKMOUSE_CHECKBOX");
258+
var oldOnClick = lockMouseCheckbox.OnClick;
259+
lockMouseCheckbox.OnClick = () =>
260+
{
261+
// Still perform the old behaviour for clicking the checkbox, before
262+
// applying the changes live.
263+
oldOnClick();
264+
265+
MakeMouseFocusSettingsLive();
266+
};
267+
256268
var mouseScrollDropdown = panel.Get<DropDownButtonWidget>("MOUSE_SCROLL");
257269
mouseScrollDropdown.OnMouseDown = _ => ShowMouseScrollDropdown(mouseScrollDropdown, gs);
258270
mouseScrollDropdown.GetText = () => gs.MouseScroll.ToString();
@@ -385,6 +397,8 @@ Action ResetInputPanel(Widget panel)
385397

386398
panel.Get<SliderWidget>("SCROLLSPEED_SLIDER").Value = gs.ViewportEdgeScrollStep;
387399
panel.Get<SliderWidget>("UI_SCROLLSPEED_SLIDER").Value = gs.UIScrollSpeed;
400+
401+
MakeMouseFocusSettingsLive();
388402
};
389403
}
390404

@@ -504,5 +518,15 @@ static bool ShowLanguageDropdown(DropDownButtonWidget dropdown)
504518
dropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 500, Game.modData.Languages, setupItem);
505519
return true;
506520
}
521+
522+
void MakeMouseFocusSettingsLive()
523+
{
524+
var gameSettings = Game.Settings.Game;
525+
526+
if (gameSettings.LockMouseWindow)
527+
Game.Renderer.GrabWindowMouseFocus();
528+
else
529+
Game.Renderer.ReleaseWindowMouseFocus();
530+
}
507531
}
508532
}

OpenRA.Renderer.Null/NullGraphicsDevice.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ public void DisableDepthBuffer() { }
4545

4646
public void SetBlendMode(BlendMode mode) { }
4747

48+
public void GrabWindowMouseFocus() { }
49+
public void ReleaseWindowMouseFocus() { }
50+
4851
public void Clear() { }
4952
public void Present() { }
5053

OpenRA.Renderer.Sdl2/Sdl2GraphicsDevice.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,10 @@ public Sdl2GraphicsDevice(Size windowSize, WindowMode windowMode)
6363

6464
window = SDL.SDL_CreateWindow("OpenRA", SDL.SDL_WINDOWPOS_CENTERED, SDL.SDL_WINDOWPOS_CENTERED, size.Width, size.Height, SDL.SDL_WindowFlags.SDL_WINDOW_OPENGL);
6565

66-
var lockWindow = Game.Settings.Game.LockMouseWindow ? SDL.SDL_bool.SDL_TRUE : SDL.SDL_bool.SDL_FALSE;
67-
SDL.SDL_SetWindowGrab(window, lockWindow);
66+
if (Game.Settings.Game.LockMouseWindow)
67+
GrabWindowMouseFocus();
68+
else
69+
ReleaseWindowMouseFocus();
6870

6971
if (windowMode == WindowMode.Fullscreen)
7072
SDL.SDL_SetWindowFullscreen(window, (uint)SDL.SDL_WindowFlags.SDL_WINDOW_FULLSCREEN);
@@ -199,6 +201,16 @@ public void SetBlendMode(BlendMode mode)
199201
ErrorHandler.CheckGlError();
200202
}
201203

204+
public void GrabWindowMouseFocus()
205+
{
206+
SDL.SDL_SetWindowGrab(window, SDL.SDL_bool.SDL_TRUE);
207+
}
208+
209+
public void ReleaseWindowMouseFocus()
210+
{
211+
SDL.SDL_SetWindowGrab(window, SDL.SDL_bool.SDL_FALSE);
212+
}
213+
202214
public void EnableScissor(int left, int top, int width, int height)
203215
{
204216
if (width < 0)

mods/cnc/chrome/settings.yaml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -318,14 +318,6 @@ Container@SETTINGS_PANEL:
318318
Height: 20
319319
Font: Regular
320320
Text: Lock mouse to window
321-
Label@LOCKMOUSE_DESC:
322-
X: 25
323-
Y: 110
324-
Width: 130
325-
Height: 25
326-
Font: Tiny
327-
Align: Right
328-
Text: (Requires restart)
329321
Label@SCROLL_SPEED_LABEL:
330322
X: PARENT_RIGHT - WIDTH - 270
331323
Y: 67

mods/ra/chrome/settings.yaml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -322,14 +322,6 @@ Background@SETTINGS_PANEL:
322322
Height: 20
323323
Font: Regular
324324
Text: Lock mouse to window
325-
Label@LOCKMOUSE_DESC:
326-
X: 25
327-
Y: 110
328-
Width: 130
329-
Height: 25
330-
Font: Tiny
331-
Align: Right
332-
Text: (Requires restart)
333325
Label@SCROLL_SPEED_LABEL:
334326
X: PARENT_RIGHT - WIDTH - 270
335327
Y: 67

0 commit comments

Comments
 (0)