Skip to content

Commit

Permalink
- When option "Auto-Start QL" is active and you try to start a 2nd ex…
Browse files Browse the repository at this point in the history
…traQL, extraQL will now bring the QL window to the foreground

  or start QL instead of bringing the extraQL GUI to the foreground. You can now always use the extraQL desktop shortcut to start QL.
- When option "Auto-Start QL" is active and the Steam Client wasn't running, extraQL no longer tries to start Steam and QL at the same
  time to avoid the misleading Steam popup about 2 Steam Clients running under different user accounts.
  • Loading branch information
PredatH0r committed Nov 24, 2015
1 parent 6a726b8 commit 4e51f40
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 14 deletions.
7 changes: 7 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ c:\program files (x86)\Steam\SteamApps\workshop\content\282440\539252269
Changelog
=========

Version 2.14
---
- When option "Auto-Start QL" is active and you try to start a 2nd extraQL, extraQL will now bring the QL window to the foreground
or start QL instead of bringing the extraQL GUI to the foreground. You can now always use the extraQL desktop shortcut to start QL.
- When option "Auto-Start QL" is active and the Steam Client wasn't running, extraQL no longer tries to start Steam and QL at the same
time to avoid the misleading Steam popup about 2 Steam Clients running under different user accounts.

Version 2.13
---
- Added config screen to enable/disable individual scripts.
Expand Down
35 changes: 28 additions & 7 deletions source/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace ExtraQL
{
public partial class MainForm : Form
{
public const string Version = "2.13";
public const string Version = "2.14";

private readonly Config config;
private readonly HttpServer server;
Expand Down Expand Up @@ -475,6 +475,16 @@ private void Startup()
}
#endregion

#region OnSecondInstanceStarted()
private void OnSecondInstanceStarted()
{
if (this.cbAutostart.Checked)
this.Launch();
else
this.SetFormVisibility(true);
}
#endregion

#region CheckIfStartedFromWorkshopFolder()
private void CheckIfStartedFromWorkshopFolder()
{
Expand Down Expand Up @@ -534,6 +544,7 @@ private void UpdateServletSettings()
this.servlets.QuakeSteamFolder = this.GetQuakeLivePath();
if (this.steamAppId != 0)
this.servlets.SteamAppId = this.steamAppId;
this.servlets.BringToFrontHandler = this.OnSecondInstanceStarted;
}
}
#endregion
Expand Down Expand Up @@ -837,12 +848,20 @@ private string GetSteamWorkshopPath()
#region StartQuakeLive()
private void StartQuakeLive()
{
this.Log("Starting Quake Live...");

var args = "";
PrepareAlternativeQuakeLiveUI(ref args);

Process.Start("steam://rungameid/" + QuakeLiveAppId + args);
var procList = Process.GetProcessesByName("quakelive_steam");
if (procList.Length > 0)
{
// bring existing QL window to front and activate it
Win32.SetWindowPos(procList[0].MainWindowHandle, Win32.HWND_TOPMOST, 0, 0, 0, 0, Win32.SWP_SHOWWINDOW | Win32.SWP_NOSIZE | Win32.SWP_NOMOVE);
Win32.SetWindowPos(procList[0].MainWindowHandle, Win32.HWND_NOTOPMOST, 0, 0, 0, 0, Win32.SWP_SHOWWINDOW | Win32.SWP_NOSIZE | Win32.SWP_NOMOVE);
}
else
{
this.Log("Starting Quake Live...");
var args = "";
PrepareAlternativeQuakeLiveUI(ref args);
Process.Start("steam://rungameid/" + QuakeLiveAppId + args);
}
this.SetFormVisibility(false);
}
#endregion
Expand Down Expand Up @@ -889,7 +908,9 @@ private void SetFormVisibility(bool visible)
if (visible)
{
this.WindowState = FormWindowState.Normal;
this.BringToFront();
this.Show();
this.Activate();
}
else
{
Expand Down
12 changes: 5 additions & 7 deletions source/Servlets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ public void Dispose()

public int SteamAppId { get { return steamworks.AppID; } set { steamworks.AppID = value; } }

public ThreadStart BringToFrontHandler { get; set; }

#region RegisterServlets()

/// <summary>
Expand Down Expand Up @@ -438,13 +440,9 @@ private void BringToFront(Stream stream, Uri uri, string request)
return;
}

form.BeginInvoke((ThreadStart)(() =>
{
this.form.Visible = true;
this.form.WindowState = FormWindowState.Normal;
this.form.BringToFront();
this.form.Activate();
}));
var handler = this.BringToFrontHandler;
if (handler != null)
form.BeginInvoke(handler);
this.HttpOk(stream, "ok");
}
#endregion
Expand Down
6 changes: 6 additions & 0 deletions source/Win32.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,14 @@ public static class Win32
[DllImport("user32.dll")]
public static extern bool ShowWindow(IntPtr handle, int flags);

[DllImport("user32.dll")]
public static extern bool SetForegroundWindow(IntPtr handle);

public delegate bool EnumWindowProc(IntPtr hWnd, IntPtr lParam);

public static int HWND_TOPMOST = -1;
public static int HWND_NOTOPMOST = -2;

public const int WM_ACTIVATE = 0x0006;
public const int WM_SETREDRAW = 0x000B;
public const int WM_CLOSE = 0x0010;
Expand Down

0 comments on commit 4e51f40

Please sign in to comment.