Skip to content

Commit c419037

Browse files
committed
Fixed the TopMost Issue
1 parent bc1ea51 commit c419037

File tree

1 file changed

+55
-22
lines changed

1 file changed

+55
-22
lines changed

InputTextX/InputTextX.cs

Lines changed: 55 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
using System.Text.RegularExpressions;
99
using Rainmeter;
1010

11-
namespace InputTextX
11+
namespace BlurInputXPlugin
1212
{
1313
// Define an enumeration for the allowed input types.
1414
public enum InputTypeOption
@@ -38,48 +38,52 @@ internal class Measure
3838
private Color fontColor = Color.Black;
3939
private float fontSize = 12f;
4040

41-
// New appearance properties.
41+
// Appearance properties.
4242
private HorizontalAlignment textAlign = HorizontalAlignment.Center;
4343
private bool isPassword = false;
4444
private FontStyle fontStyleParam = FontStyle.Regular;
4545
private string fontFace = "Segoe UI"; // default or custom font family name
4646

47-
// New behavioral properties.
47+
// Behavioral properties.
4848
private bool multiline = false;
4949
private int allowScroll = 0; // 1 = allow scrollbars in multiline
5050
private int inputLimit = 0; // 0 means no limit
5151
private string defaultValue = "";
5252

53-
// New input filtering properties.
53+
// Input filtering properties.
5454
private InputTypeOption inputType = InputTypeOption.String;
5555
private string allowedChars = ""; // used if inputType==Custom
5656

57-
// New action parameters.
57+
// Action parameters.
5858
private string onDismissAction = "";
5959
private string onEnterAction = "";
6060
private string onESCAction = "";
6161
private string onInvalidAction = "";
6262

63-
// New offset parameters.
63+
// Offset parameters.
6464
private int offsetX = 0;
6565
private int offsetY = 0;
6666

67-
// New border parameters.
67+
// Border parameters.
6868
private int allowBorder = 0;
6969
private Color borderColor = Color.Black;
7070
private int borderThickness = 2;
7171

72-
// New numeric range parameters.
72+
// Numeric range parameters.
7373
private double minValue = double.MinValue;
7474
private double maxValue = double.MaxValue;
7575

76-
// New TopMost parameter.
76+
// TopMost parameter.
7777
private int topMost = 1;
7878

79+
// Logging parameter.
80+
private int logging = 0;
81+
7982
internal void Reload(API api, ref double maxValueOut)
8083
{
8184
_api = api;
82-
_api.Log(API.LogType.Notice, "Reloading measure...");
85+
if (logging == 1)
86+
_api.Log(API.LogType.Notice, "Reloading measure...");
8387
unFocusDismiss = api.ReadInt("UnFocusDismiss", 1);
8488

8589
inputWidth = api.ReadInt("W", 300);
@@ -137,8 +141,10 @@ internal void Reload(API api, ref double maxValueOut)
137141
maxValue = api.ReadDouble("MaxValue", double.MaxValue);
138142

139143
topMost = api.ReadInt("TopMost", 1);
144+
logging = api.ReadInt("Logging", 0);
140145

141-
_api.Log(API.LogType.Notice, $"Reload complete. Input dimensions: {inputWidth}x{inputHeight}");
146+
if (logging == 1)
147+
_api.Log(API.LogType.Notice, $"Reload complete. Input dimensions: {inputWidth}x{inputHeight}, TopMost: {topMost}, Logging: {logging}");
142148
}
143149

144150
internal double Update() => currentText.Length;
@@ -149,18 +155,39 @@ internal void ExecuteCommand(string command)
149155
if (string.IsNullOrEmpty(command))
150156
return;
151157

158+
if (command.Equals("Stop", StringComparison.InvariantCultureIgnoreCase))
159+
{
160+
if (logging == 1)
161+
_api.Log(API.LogType.Notice, "ExecuteCommand: Stop command received.");
162+
if (inputOverlay != null && !inputOverlay.IsDisposed)
163+
{
164+
inputOverlay.Invoke(new Action(() => inputOverlay.Close()));
165+
if (logging == 1)
166+
_api.Log(API.LogType.Notice, "Input overlay stopped.");
167+
}
168+
else if (logging == 1)
169+
{
170+
_api.Log(API.LogType.Notice, "No active input overlay to stop.");
171+
}
172+
return;
173+
}
174+
152175
if (command.Equals("Start", StringComparison.InvariantCultureIgnoreCase))
153176
{
154-
_api.Log(API.LogType.Notice, "ExecuteCommand: Starting input overlay...");
177+
if (logging == 1)
178+
_api.Log(API.LogType.Notice, "ExecuteCommand: Start command received.");
179+
// Always show the input overlay (regardless of logging mode)
155180
if (inputThread == null || !inputThread.IsAlive)
156181
{
157182
inputThread = new Thread(() =>
158183
{
159184
int baseX = int.Parse(_api.ReplaceVariables("#CURRENTCONFIGX#"));
160185
int baseY = int.Parse(_api.ReplaceVariables("#CURRENTCONFIGY#"));
161-
_api.Log(API.LogType.Notice, $"Base coordinates: {baseX},{baseY}");
162-
_api.Log(API.LogType.Notice, $"Offset: {offsetX},{offsetY}");
163-
186+
if (logging == 1)
187+
{
188+
_api.Log(API.LogType.Notice, $"Base coordinates: {baseX},{baseY}");
189+
_api.Log(API.LogType.Notice, $"Offset: {offsetX},{offsetY}");
190+
}
164191
string overlayWidthStr = _api.ReplaceVariables("#CURRENTCONFIGWIDTH#");
165192
string overlayHeightStr = _api.ReplaceVariables("#CURRENTCONFIGHEIGHT#");
166193
int overlayWidth = 400, overlayHeight = 300;
@@ -169,12 +196,16 @@ internal void ExecuteCommand(string command)
169196

170197
int overlayX = baseX;
171198
int overlayY = baseY;
172-
_api.Log(API.LogType.Notice, $"Overlay bounds: {overlayX},{overlayY} {overlayWidth}x{overlayHeight}");
199+
if (logging == 1)
200+
_api.Log(API.LogType.Notice, $"Overlay bounds: {overlayX},{overlayY} {overlayWidth}x{overlayHeight}");
173201

174202
Action<string> execCallback = (action) =>
175203
{
176204
if (!string.IsNullOrEmpty(action))
177-
_api.Log(API.LogType.Notice, "Executing action: " + action);
205+
{
206+
if (logging == 1)
207+
_api.Log(API.LogType.Notice, "Executing action: " + action);
208+
}
178209
};
179210

180211
inputOverlay = new InputOverlay(
@@ -194,7 +225,8 @@ internal void ExecuteCommand(string command)
194225
inputOverlay.TextSubmitted += (s, text) =>
195226
{
196227
currentText = text;
197-
_api.Log(API.LogType.Notice, "Text submitted: " + text);
228+
if (logging == 1)
229+
_api.Log(API.LogType.Notice, "Text submitted: " + text);
198230
};
199231
Application.Run(inputOverlay);
200232
});
@@ -214,7 +246,8 @@ internal void Unload()
214246
}
215247
catch (Exception ex)
216248
{
217-
_api.Log(API.LogType.Notice, "Error during Unload: " + ex.Message);
249+
if (logging == 1)
250+
_api.Log(API.LogType.Notice, "Error during Unload: " + ex.Message);
218251
}
219252
}
220253

@@ -497,7 +530,6 @@ public InputOverlay(
497530
this.Show();
498531
this.DesktopLocation = new Point(inputX, inputY);
499532

500-
// Set window Z-order based on _topMost value.
501533
if (_topMost == 1)
502534
{
503535
SetWindowPos(this.Handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
@@ -506,9 +538,10 @@ public InputOverlay(
506538
}
507539
else
508540
{
509-
SetWindowPos(this.Handle, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
541+
// Bring the input overlay window above the overlay form.
510542
SetWindowPos(overlayForm.Handle, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
511-
_executeActionCallback?.Invoke("InputOverlay: Windows set to NOT TOPMOST.");
543+
SetWindowPos(this.Handle, overlayForm.Handle, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
544+
_executeActionCallback?.Invoke("InputOverlay: Windows set to NOT TOPMOST; input overlay brought to front.");
512545
}
513546
}
514547

0 commit comments

Comments
 (0)