From cca1593f79d503661c2aab4b577db5293cfe4a88 Mon Sep 17 00:00:00 2001 From: FellippeHeitor Date: Thu, 12 Aug 2021 23:00:43 -0300 Subject: [PATCH] Switches focus to IDE automatically when breakpoint is reached. Windows-only. --- internal/c/libqb.cpp | 7 +++++++ internal/c/qbx.cpp | 1 + internal/support/vwatch/vwatch.bm | 15 +++++++++++++++ source/ide/ide_methods.bas | 14 ++++++++++++-- 4 files changed, 35 insertions(+), 2 deletions(-) diff --git a/internal/c/libqb.cpp b/internal/c/libqb.cpp index 209e0b81d..2816580f3 100644 --- a/internal/c/libqb.cpp +++ b/internal/c/libqb.cpp @@ -12675,6 +12675,13 @@ qbs *func__title(){ } } +void set_foreground_window(ptrszint i) { + #ifdef QB64_WINDOWS + BOOL result = SetForegroundWindow((HWND) i); + #endif + return; +} + int32 func__hasfocus() { #ifdef QB64_GUI #ifdef QB64_WINDOWS diff --git a/internal/c/qbx.cpp b/internal/c/qbx.cpp index 37e8b9bd4..055b79d88 100755 --- a/internal/c/qbx.cpp +++ b/internal/c/qbx.cpp @@ -187,6 +187,7 @@ extern int32 func__controlchr(); extern void sub__blink(int32); extern int32 func__blink(); extern int32 func__hasfocus(); +extern void set_foreground_window(ptrszint i); extern qbs *func__title(); extern int32 func__handle(); extern int32 func__fileexists(qbs*); diff --git a/internal/support/vwatch/vwatch.bm b/internal/support/vwatch/vwatch.bm index a564d9393..1b95244c3 100644 --- a/internal/support/vwatch/vwatch.bm +++ b/internal/support/vwatch/vwatch.bm @@ -4,6 +4,7 @@ SUB vwatch (globalVariables AS _OFFSET, localVariables AS _OFFSET) STATIC AS LONG vw_ideHost, vw_breakpointCount, vw_skipCount, vw_timeout, vw_startLevel, vw_lastLine STATIC AS LONG vw_runToLine STATIC AS _BYTE vw_pauseMode, vw_stepOver, vw_bypass, vw_setNextLine + STATIC AS _OFFSET vw_idehwnd STATIC vw_buffer$, vw_endc$ DIM AS LONG vw_i, vw_tempIndex, vw_localIndex, vw_varSize, vw_sequence DIM AS _OFFSET vw_address @@ -18,6 +19,12 @@ SUB vwatch (globalVariables AS _OFFSET, localVariables AS _OFFSET) FUNCTION stop_program_state& END DECLARE + $IF WIN THEN + DECLARE DYNAMIC LIBRARY "user32" + FUNCTION SetForegroundWindow& (BYVAL hWnd AS _OFFSET) + END DECLARE + $END IF + IF vw_bypass THEN EXIT SUB vwatch_goto = 0 @@ -32,6 +39,8 @@ SUB vwatch (globalVariables AS _OFFSET, localVariables AS _OFFSET) 'send this binary's path/exe name vw_cmd$ = "me:" + COMMAND$(0) GOSUB SendCommand + vw_cmd$ = "hwnd:" + _MK$(_OFFSET, _WINDOWHANDLE) + GOSUB SendCommand DO GOSUB GetCommand @@ -59,6 +68,8 @@ SUB vwatch (globalVariables AS _OFFSET, localVariables AS _OFFSET) vw_temp$ = MID$(vw_value$, vw_i * 4 - 3, 4) vwatch_breakpoints(CVL(vw_temp$)) = -1 NEXT + CASE "hwnd" + vw_idehwnd = _CV(_OFFSET, vw_value$) CASE "skip count" vw_skipCount = CVL(vw_value$) CASE "skip list" @@ -167,6 +178,10 @@ SUB vwatch (globalVariables AS _OFFSET, localVariables AS _OFFSET) vw_cmd$ = "current sub:" + LEFT$(vwatch_stack(vwatch_sublevel), INSTR(vwatch_stack(vwatch_sublevel), ",") - 1) GOSUB SendCommand + $IF WIN THEN + vw_i = SetForegroundWindow&(vw_idehwnd) + $END IF + DO 'main loop IF stop_program_state& THEN vw_bypass = -1: EXIT DO SELECT CASE vw_cmd$ diff --git a/source/ide/ide_methods.bas b/source/ide/ide_methods.bas index c7cca00b7..65d71b1d3 100644 --- a/source/ide/ide_methods.bas +++ b/source/ide/ide_methods.bas @@ -6345,6 +6345,11 @@ SUB DebugMode STATIC buffer$ STATIC endc$ STATIC currentSub$ + STATIC debuggeehwnd AS _OFFSET + + DECLARE LIBRARY + SUB set_foreground_window (BYVAL hwnd AS _OFFSET) + END DECLARE timeout = 10 _KEYCLEAR @@ -6395,6 +6400,7 @@ SUB DebugMode callstacklist$ = "" buffer$ = "" debugClient& = 0 + debuggeepid = 0 IF LEN(variableWatchList$) = 0 THEN totalVisibleVariables = 0 @@ -6518,14 +6524,17 @@ SUB DebugMode CLOSE #debugClient& WHILE _MOUSEINPUT: WEND EXIT SUB - ELSE - EXIT DO END IF + CASE "hwnd" + debuggeehwnd = _CV(_OFFSET, value$) + EXIT DO END SELECT LOOP cmd$ = "vwatch:ok" GOSUB SendCommand + cmd$ = "hwnd:" + _MK$(_OFFSET, _WINDOWHANDLE) + GOSUB SendCommand cmd$ = "line count:" + MKL$(iden) GOSUB SendCommand @@ -7173,6 +7182,7 @@ SUB DebugMode setStatusMessage 1, "Running...", 10 GOSUB UpdateDisplay dummy = DarkenFGBG(1) + set_foreground_window debuggeehwnd CASE 16384 'F6 F6: requestStepOut: