Skip to content

Commit 0e186b4

Browse files
committed
Merge pull request nwjs#398 from zhchbin/issue251
[WIN][GTK]hide the window from task bar while keeping it shown
2 parents e0c9a02 + 51771f2 commit 0e186b4

File tree

10 files changed

+96
-0
lines changed

10 files changed

+96
-0
lines changed

src/api/window/window.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ void Window::Call(const std::string& method,
101101
bool top;
102102
if (arguments.GetBoolean(0, &top))
103103
shell_->window()->SetAlwaysOnTop(top);
104+
} else if (method == "SetShowInTaskbar" ) {
105+
bool show;
106+
if (arguments.GetBoolean(0, &show))
107+
shell_->window()->SetShowInTaskbar(show);
104108
} else if (method == "MoveTo") {
105109
int x, y;
106110
if (arguments.GetInteger(0, &x) &&

src/api/window_bindings.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,11 @@ Window.prototype.setAlwaysOnTop = function(flag) {
289289
CallObjectMethod(this, 'SetAlwaysOnTop', [ Boolean(flag) ]);
290290
}
291291

292+
Window.prototype.setShowInTaskbar = function(flag) {
293+
flag = Boolean(flag);
294+
CallObjectMethod(this, 'SetShowInTaskbar', [ flag ]);
295+
}
296+
292297
Window.prototype.requestAttention = function(flash) {
293298
flash = Boolean(flash);
294299
CallObjectMethod(this, 'RequestAttention', [ flash ]);

src/browser/native_window.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@ void NativeWindow::InitFromManifest(base::DictionaryValue* manifest) {
113113
if (manifest->GetBoolean(switches::kmAlwaysOnTop, &top) && top) {
114114
SetAlwaysOnTop(true);
115115
}
116+
bool showInTaskbar;
117+
if (manifest->GetBoolean(switches::kmShowInTaskbar, &showInTaskbar) &&
118+
!showInTaskbar) {
119+
SetShowInTaskbar(false);
120+
}
116121
bool fullscreen;
117122
if (manifest->GetBoolean(switches::kmFullscreen, &fullscreen) && fullscreen) {
118123
SetFullscreen(true);

src/browser/native_window.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ class NativeWindow {
8181
virtual void SetMaximumSize(int width, int height) = 0;
8282
virtual void SetResizable(bool resizable) = 0;
8383
virtual void SetAlwaysOnTop(bool top) = 0;
84+
virtual void SetShowInTaskbar(bool show = true) = 0;
8485
virtual void SetPosition(const std::string& position) = 0;
8586
virtual void SetPosition(const gfx::Point& position) = 0;
8687
virtual gfx::Point GetPosition() = 0;

src/browser/native_window_gtk.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,10 @@ void NativeWindowGtk::SetAlwaysOnTop(bool top) {
236236
gtk_window_set_keep_above(window_, top ? TRUE : FALSE);
237237
}
238238

239+
void NativeWindowGtk::SetShowInTaskbar(bool show) {
240+
gtk_window_set_skip_taskbar_hint(window_, show ? FALSE : TRUE);
241+
}
242+
239243
void NativeWindowGtk::SetPosition(const std::string& position) {
240244
if (position == "center")
241245
gtk_window_set_position(window_, GTK_WIN_POS_CENTER);

src/browser/native_window_gtk.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class NativeWindowGtk : public NativeWindow {
5353
virtual void SetMaximumSize(int width, int height) OVERRIDE;
5454
virtual void SetResizable(bool resizable) OVERRIDE;
5555
virtual void SetAlwaysOnTop(bool top) OVERRIDE;
56+
virtual void SetShowInTaskbar(bool show = true) OVERRIDE;
5657
virtual void SetPosition(const std::string& position) OVERRIDE;
5758
virtual void SetPosition(const gfx::Point& position) OVERRIDE;
5859
virtual gfx::Point GetPosition() OVERRIDE;

src/browser/native_window_win.cc

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,12 @@
2020

2121
#include "content/nw/src/browser/native_window_win.h"
2222

23+
#include <shobjidl.h>
24+
2325
#include "base/utf_string_conversions.h"
2426
#include "base/values.h"
27+
#include "base/win/scoped_comptr.h"
28+
#include "base/win/windows_version.h"
2529
#include "base/win/wrapped_window_proc.h"
2630
#include "chrome/browser/platform_util.h"
2731
#include "chrome/common/extensions/draggable_region.h"
@@ -347,6 +351,43 @@ void NativeWindowWin::SetResizable(bool resizable) {
347351
::SetWindowLong(window_->GetNativeView(), GWL_STYLE, style);
348352
}
349353

354+
void NativeWindowWin::SetShowInTaskbar(bool show) {
355+
if (show == false && base::win::GetVersion() < base::win::VERSION_VISTA) {
356+
if (hidden_owner_window_.get() == NULL) {
357+
hidden_owner_window_.reset(new HiddenOwnerWindow());
358+
}
359+
360+
// Change the owner of native window. Only needed on Windows XP.
361+
::SetWindowLong(window_->GetNativeView(),
362+
GWL_HWNDPARENT,
363+
(LONG)hidden_owner_window_->hwnd());
364+
}
365+
366+
base::win::ScopedComPtr<ITaskbarList> taskbar;
367+
HRESULT result = taskbar.CreateInstance(CLSID_TaskbarList, NULL,
368+
CLSCTX_INPROC_SERVER);
369+
if (FAILED(result)) {
370+
VLOG(1) << "Failed creating a TaskbarList object: " << result;
371+
return;
372+
}
373+
374+
result = taskbar->HrInit();
375+
if (FAILED(result)) {
376+
LOG(ERROR) << "Failed initializing an ITaskbarList interface.";
377+
return;
378+
}
379+
380+
if (show)
381+
result = taskbar->AddTab(window_->GetNativeWindow());
382+
else
383+
result = taskbar->DeleteTab(window_->GetNativeWindow());
384+
385+
if (FAILED(result)) {
386+
LOG(ERROR) << "Failed to change the show in taskbar attribute";
387+
return;
388+
}
389+
}
390+
350391
void NativeWindowWin::SetAlwaysOnTop(bool top) {
351392
window_->SetAlwaysOnTop(top);
352393
}

src/browser/native_window_win.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "content/nw/src/browser/native_window.h"
2525

2626
#include "third_party/skia/include/core/SkRegion.h"
27+
#include "ui/base/win/window_impl.h"
2728
#include "ui/gfx/image/image_skia.h"
2829
#include "ui/gfx/rect.h"
2930
#include "ui/views/focus/widget_focus_manager.h"
@@ -37,6 +38,31 @@ namespace nw {
3738

3839
class NativeWindowToolbarWin;
3940

41+
///////////////////////////////////////////////////////////////////////////////
42+
//
43+
// HiddenOwnerWindow
44+
// This class is used as a hidden owner window for NativeWindowWin.
45+
// Note: The reason for using it is on Windows XP, while using the
46+
// ITaskbarList::DeleteTab to remove the icon from the taskbar, the icon will
47+
// appear in taskbar again when it blur and being focused again. This class
48+
// object will only exist on Windows XP. See the implementation about
49+
// |NativeWindowWin::SetShowInTaskbar|.
50+
//
51+
///////////////////////////////////////////////////////////////////////////////
52+
class HiddenOwnerWindow : public ui::WindowImpl {
53+
public:
54+
HiddenOwnerWindow() {
55+
Init(NULL, gfx::Rect());
56+
}
57+
58+
~HiddenOwnerWindow() {
59+
DestroyWindow(hwnd());
60+
}
61+
62+
BEGIN_MSG_MAP_EX(HiddenOwnerWindow)
63+
END_MSG_MAP()
64+
};
65+
4066
class NativeWindowWin : public NativeWindow,
4167
public views::WidgetFocusChangeListener,
4268
public views::WidgetDelegateView {
@@ -67,6 +93,7 @@ class NativeWindowWin : public NativeWindow,
6793
virtual void SetMaximumSize(int width, int height) OVERRIDE;
6894
virtual void SetResizable(bool resizable) OVERRIDE;
6995
virtual void SetAlwaysOnTop(bool top) OVERRIDE;
96+
virtual void SetShowInTaskbar(bool show = true) OVERRIDE;
7097
virtual void SetPosition(const std::string& position) OVERRIDE;
7198
virtual void SetPosition(const gfx::Point& position) OVERRIDE;
7299
virtual gfx::Point GetPosition() OVERRIDE;
@@ -137,6 +164,10 @@ class NativeWindowWin : public NativeWindow,
137164

138165
scoped_ptr<SkRegion> draggable_region_;
139166

167+
// This is only useful on Windows XP. Hidden owner window for Windows XP to
168+
// let SetShowInTaskbar work like on Windows 7.
169+
scoped_ptr<HiddenOwnerWindow> hidden_owner_window_;
170+
140171
// The window's menubar.
141172
api::Menu* menu_;
142173

src/common/shell_switches.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ const char kmResizable[] = "resizable";
6868
const char kmAsDesktop[] = "as_desktop";
6969
const char kmFullscreen[] = "fullscreen";
7070

71+
// Make windows icon hide show or hide in taskbar.
72+
const char kmShowInTaskbar[] = "show_in_taskbar";
73+
7174
// Start with the kiosk mode, see Opera's page for description:
7275
// http://www.opera.com/support/mastering/kiosk/
7376
const char kmKiosk[] = "kiosk";

src/common/shell_switches.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ extern const char kmMaxHeight[];
4343
extern const char kmResizable[];
4444
extern const char kmAsDesktop[];
4545
extern const char kmFullscreen[];
46+
extern const char kmShowInTaskbar[];
4647
extern const char kmKiosk[];
4748
extern const char kmAlwaysOnTop[];
4849

0 commit comments

Comments
 (0)