Skip to content

Commit

Permalink
feat: support topmost.(windows&linux)
Browse files Browse the repository at this point in the history
  • Loading branch information
wcb33 committed Jun 25, 2021
1 parent a5ce2e2 commit 985069d
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 1 deletion.
6 changes: 6 additions & 0 deletions bitsdojo_window_linux/lib/src/native_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ typedef Void TSetWindowTitle(IntPtr window, Pointer<Utf8> title);
typedef DSetWindowTitle = void Function(int window, Pointer<Utf8> title);
final DSetWindowTitle setWindowTitle = _theAPI.ref.setWindowTitle.asFunction();

// setTopmost
typedef Void TSetTopmost(IntPtr window, Int32 topmost);
typedef DSetTopmost = void Function(int window, int topmost);
final DSetTopmost setTopmost = _theAPI.ref.setTopMost.asFunction();

class BDWAPI extends Struct {
external Pointer<NativeFunction<TGetAppWindowHandle>> getAppWindowHandle;
external Pointer<NativeFunction<TGetScreenRect>> getScreenRect;
Expand All @@ -110,6 +115,7 @@ class BDWAPI extends Struct {
external Pointer<NativeFunction<TMaximizeWindow>> maximizeWindow;
external Pointer<NativeFunction<TUnmaximizeWindow>> unmaximizeWindow;
external Pointer<NativeFunction<TSetWindowTitle>> setWindowTitle;
external Pointer<NativeFunction<TSetTopmost>> setTopMost;
}

typedef Pointer<BDWAPI> TBitsdojoWindowAPI();
Expand Down
6 changes: 6 additions & 0 deletions bitsdojo_window_linux/lib/src/window.dart
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,12 @@ class GtkWindow extends DesktopWindow {
handle!, _maxSize!.width.toInt(), _maxSize!.height.toInt());
}

@override
set topmost(bool topmost) {
if (!isValidHandle(handle, "set topmost")) return;
native.setTopmost(handle!, topmost ? 1 : 0);
}

@override
set size(Size newSize) {
if (!isValidHandle(handle, "set size")) return;
Expand Down
3 changes: 2 additions & 1 deletion bitsdojo_window_linux/linux/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ BDWAPI _theAPI = {
minimizeWindow,
maximizeWindow,
unmaximizeWindow,
setWindowTitle
setWindowTitle,
setTopmost
};

} // namespace bitsdojo_window
Expand Down
1 change: 1 addition & 0 deletions bitsdojo_window_linux/linux/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ typedef struct _BDWAPI {
TMaximizeWindow maximizeWindow;
TUnmaximizeWindow unmaximizeWindow;
TSetWindowTitle setWindowTitle;
TSetTopmost setTopmost;
} BDWAPI;

} // namespace bitsdojo_window
Expand Down
4 changes: 4 additions & 0 deletions bitsdojo_window_linux/linux/api_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,4 +209,8 @@ void setWindowTitle(GtkWindow* window, const gchar* title) {
g_idle_add_full(G_PRIORITY_HIGH_IDLE, setWindowTitleProc, params, NULL);
}

void setTopmost(GtkWindow* window, int topmost){
gtk_window_set_keep_above(topmost == 1 ? TRUE : FALSE);
}

} // namespace bitsdojo_window
3 changes: 3 additions & 0 deletions bitsdojo_window_linux/linux/api_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ namespace bitsdojo_window {

typedef void (*TSetWindowTitle)(GtkWindow*, const gchar *);
void setWindowTitle(GtkWindow* window, const gchar *title);

typedef void (*TSetTopmost)(GtkWindow*, int);
void setTopmost(GtkWindow* window,int topmost);
}

#endif // _BDW_API_IMPL_
6 changes: 6 additions & 0 deletions bitsdojo_window_macos/lib/src/window.dart
Original file line number Diff line number Diff line change
Expand Up @@ -238,4 +238,10 @@ class MacOSWindow extends DesktopWindow {
if (!isValidHandle(handle, "maximizeOrRestore")) return;
maximizeOrRestoreWindow(handle!);
}

@override
set topmost(bool topmost) {
// TODO: implement topmost
throw UnimplementedError();
}
}
2 changes: 2 additions & 0 deletions bitsdojo_window_platform_interface/lib/window.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ abstract class DesktopWindow {
set minSize(Size? newSize);
set maxSize(Size? newSize);

set topmost(bool topmost);

Alignment? get alignment;
set alignment(Alignment? newAlignment);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ class NotImplementedWindow extends DesktopWindow {
throw UnimplementedError('maxSize setter has not been implemented.');
}

set topmost(bool toomost) {
throw UnimplementedError('topmost setter has not been implemented.');
}

Alignment get alignment {
throw UnimplementedError('alignment getter has not been implemented.');
}
Expand Down
9 changes: 9 additions & 0 deletions bitsdojo_window_windows/lib/src/window.dart
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,15 @@ class WinWindow extends WinDesktopWindow {
PostMessage(handle!, WM_SYSCOMMAND, SC_MINIMIZE, 0);
}

@override
set topmost(bool topmost) {
if (!isValidHandle(handle, "topmost")) return;

// HWND_TOPMOST (HWND)-1
var flag = topmost ? -1 : 0;
SetWindowPos(handle!, flag, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
}

void restore() {
if (!isValidHandle(handle, "restore")) return;
PostMessage(handle!, WM_SYSCOMMAND, SC_RESTORE, 0);
Expand Down

0 comments on commit 985069d

Please sign in to comment.