PDA

View Full Version : Grabbing ahold of the focus, screen, keyboard and their soul



Thrantor
13th September 2006, 16:44
Ok, I've got an application that needs to grab ahold of EVERYTHING until a user does the correct thing. I need it to pop back up to the foreground if someone minimizes it or clicks on another window. The first thing it needs to do is explicitly pop to the front.

Thoughts suggestions? And warning. I'm a Qt newbie who just got handed this project cause the previous guy left.

pherthyl
13th September 2006, 21:39
I sense something evil here.... Ok, it's possible that you could have a legit use for this, but this smells of bad user interface design.

Save yourself a whole lot of trouble by making the window maximized, always on top, and without a window frame (have a look at Window flags for QWidget (in the constructor)). This removes the ability to click on most apps already. Of course, the user could still get around it if they really wanted to, but you can prevent a lot of that with some event capturing (QWidget::leaveEvent(), etc)

Thrantor
13th September 2006, 22:03
Naw... Nothing evil here. The reason we want to take over is that the system will be in an unusable state at the time. The target users are people with barely any training using the machine. So we need to be as bloody obvious and as bulletproof as possible. Hence trying to take away as many options as possible. Basically, we're telling them when to change the printer paper. The only reason we want the message is because we've already had users of the test app complain that the machine stopped printing and just sat there. We implemented a system message to their TTY to tell them to change the paper... And some of them still ignored it. Not allowing them to do anything else until the fix the problem... Sadly seems to be the only thing that might work.

I'm going to try first with a QmessageBox and see how they react to that. We might not have to go crazy with the not letting them do anything... But we'll see how the tests go

wysota
13th September 2006, 22:15
If your application runs under KDE, you might want to reuse its functionality for locking the screen using DCOP interface... If that's not an option, maybe you should take a look at that part of KDE sources which actually implements the lock.

hayati
14th September 2006, 10:56
QApplication x11EventFilter ( XEvent* e )
function may do what you want. But this time you need to have a programming context about X11 functions. when your application's window lost focus then your window also gets an event.

you may chance to decide which events you can hook. possible focus lost event is most appropriate for you.

i tested this function when a window lost focus then XEvent's type member gets the value of 10.


//e->type == 10

but unfortunately, i don't know how to make a window to be on top and visible over other windows.

raise(), setActiveWindow(), show() functions don't guaranty the visibility of the window. But blink effect appears on menu bar instead :(

pherthyl
14th September 2006, 18:56
To make a widget that is always on top:
QWidget::setWindowFlags(Qt::WindowStaysOnTopHint)
You might also need to pass Qt::X11BypassWindowManagerHint for this to work.

for no frame (and therefore no maximize/minimize/close buttons)
Qt::FramelessWindowHint

wysota
14th September 2006, 21:02
In this particular situation I would just show the widget full screen instead of forcing it on top.