|
|
Home » U++ Library support » TopWindow&PopUp, TrayIcon » [FEATURE] Setting TopWindow to urgent/flashing state
[FEATURE] Setting TopWindow to urgent/flashing state [message #30883] |
Thu, 27 January 2011 16:50 |
|
Hi everyone
Today I realized that U++ provides no way how to set the window into the "flashing state" that is often used in applications (e.g. IM apps) to attract user attention in an unobtrusive manner (certainly less disturbing than bringing the window to foreground ).
So I propose to add methods Urgent(bool b = true) and IsUrgent() to TopWindow. The code is fairly simple:
In TopWindow.h:class TopWindow : public Ctrl {
// ...
bool frameless:1;
bool urgent:1; // added
byte state;
// ...
TopWindow& FrameLess(bool b = true) { frameless = b; return *this; }
bool IsFrameLess() const { return frameless; }
TopWindow& Urgent(bool b = true); // added
bool IsUrgent() const { return urgent; } // added
TopWindow& NoAccessKeysDistribution() { dokeys = false; return *this; }
TopWindow& NoCloseBox(bool b = true) { noclosebox = b; return *this; }
// ...
}
In TopWindow.cpp:TopWindow& TopWindow::Urgent(bool b)
{
GuiLock __;
urgent = b;
SyncCaption();
return *this;
}
In ToWinX11.cpp:void TopWindow::SyncCaption0()
{
// ...
wm_hints->flags = InputHint|WindowGroupHint|StateHint;
if(IsTopMost()) urgent = false; // added
if(urgent) wm_hints->flags |= XUrgencyHint; // added
wm_hints->initial_state = NormalState;
wm_hints->input = XTrue;
// ...
}
In TopWin32.cppvoid TopWindow::SyncCaption0()
{
// ...
if(hwnd) {
::SetWindowLong(hwnd, GWL_STYLE, style);
::SetWindowLong(hwnd, GWL_EXSTYLE, exstyle);
SyncTitle();
// added:
if(IsTopMost()) urgent = false;
FLASHWINFO fi;
fi.cbSize = sizeof(fi);
fi.hwnd = GetHWND();
fi.dwFlags = urgent?FLASHW_TIMERNOFG|FLASHW_ALL:FLASHW_STOP;
fi.uCount = 0;
fi.dwTimeout = 0;
FlashWindowEx(&fi);
}
// ...
}
The behavior should be fairly standard: If you call Urgent(true); then the window title and item in taskbar are flashing until either Urgent(false); is called or the window is taken to foreground. If Urgent(true); is called on active window then it has no effect. The win32 implementation might have some bugs, I didn't test it on windows (and it is not implemented correctly in wine ).
If you are wandering why I stumbled upon this, it is because it would be nice if theide would use it instead of popping up on finished builds and when breakpoint is hit when debugging.
Best regards,
Honza
[Updated on: Thu, 27 January 2011 17:12] Report message to a moderator
|
|
|
|
Re: [FEATURE] Setting TopWindow to urgent/flashing state [message #30895 is a reply to message #30883] |
Thu, 27 January 2011 22:16 |
|
Testedon windows Vista and it works fine
Only problem is when compiling with Mingw, there is probably some bug in mingw headers, causing FLASHWINFO to be undeclared. So to fix it, following must be added at te top of TopWin32.cpp:#ifdef COMPILER_MINGW
extern "C"{
struct FLASHWINFO {
UINT cbSize;
HWND hwnd;
DWORD dwFlags;
UINT uCount;
DWORD dwTimeout;
};
WINUSERAPI BOOL WINAPI FlashWindowEx(FLASHWINFO*);
}
#define FLASHW_STOP 0
#define FLASHW_CAPTION 0x00000001
#define FLASHW_TRAY 0x00000002
#define FLASHW_ALL (FLASHW_CAPTION | FLASHW_TRAY)
#define FLASHW_TIMER 0x00000004
#define FLASHW_TIMERNOFG 0x0000000C
#endif
Honza
|
|
|
Goto Forum:
Current Time: Wed Sep 25 03:38:37 CEST 2024
Total time taken to generate the page: 0.02909 seconds
|
|
|