Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

It might sound ridiculous, but I want to prevent closing a window in Ubuntu. I want to provide to my users a highly secure environment, without any desktop environment with just one window open. Now I want to make sure user can't close that window. Is there any way to hack around with compiz so that there is no way a user can close the window. Not by pressing close button, not by pressing alt+f4 etc.?

I am open to use any window manager amongst those available in 12.04. Either of compiz, metacity, and others. I am also willing to hack around with source code if required.

EDIT: Just disabling ALT+F4 from OS doesn't solve the problem. That is because some applications issue close commands on pressing ALT+F4 even before the event is bubbled to OS. I need a way by which the ability to close the window is taken away from application itself.

share|improve this question

2 Answers 2

As I know and as you said there are two ways to prevent closing a window. disable close button and alt+f4

To disable close, minimize, maximize button in Gnome : Alt+F2 Enter: gconf-editor Go to app > metacity > general Double click on button layout you will see menu:minimize,maximize,close

you can also use Gnome tweak tool to enable disable menu and button icons which is available here https://live.gnome.org/GnomeTweakTool

I think you can remove the ones you don't want from there.

To disable atl+f4 : In the menu go to System - Preferences - Personal -Keyboard Shortcuts disable the shortcuts which you want

share|improve this answer
    
Can't find Button Layout inside > general –  Juzer Ali Sep 1 '12 at 19:20
    
And btw that will still not prevent closing the window through Ctrl+F4. Since Ctrl+F4 is application specific. We need to take the privilege of closing the window away from the application in which it is contained. –  Juzer Ali Sep 2 '12 at 6:36

Compiz provides this functionality using the Window Rules plugin. You specify which windows to match (by name, type, ID, etc.) and then you can apply rules to those windows. One of the rules is to prevent the window from closing. I used this for a long time and can confirm it works well and prevents keyboard shortcuts, close button, and right click and close on the task bar. Pretty much a low-level way of preventing a window from closing.

You can also use xprop to do this (Compiz not required). An example:

xprop -format _NET_WM_ALLOWED_ACTIONS 32a -set _NET_WM_ALLOWED_ACTIONS "_NET_WM_ACTION_MOVE, _NET_WM_ACTION_RESIZE, _NET_WM_ACTION_FULLSCREEN, _NET_WM_ACTION_MINIMIZE, _NET_WM_ACTION_SHADE, _NET_WM_ACTION_MAXIMIZE_HORZ, _NET_WM_ACTION_MAXIMIZE_VERT, _NET_WM_ACTION_CHANGE_DESKTOP, _NET_WM_ACTION_ABOVE, _NET_WM_ACTION_BELOW"

Combined with locating the window ID to use:

window_id=`wmctrl -l | grep Insert_Name_of_Window | head -n1 | cut -d" " -f1`
xprop -id "$window_id" -format _NET_WM_ALLOWED_ACTIONS 32a -set _NET_WM_ALLOWED_ACTIONS "_NET_WM_ACTION_MOVE, _NET_WM_ACTION_RESIZE, _NET_WM_ACTION_FULLSCREEN, _NET_WM_ACTION_MINIMIZE, _NET_WM_ACTION_SHADE, _NET_WM_ACTION_MAXIMIZE_HORZ, _NET_WM_ACTION_MAXIMIZE_VERT, _NET_WM_ACTION_CHANGE_DESKTOP, _NET_WM_ACTION_ABOVE, _NET_WM_ACTION_BELOW"

Note that what xprop is modifying here are allowed actions for the window, not the window's state. So if you want to prevent a window from being minimized, remove the _NET_WM_ACTION_MINIMIZE action, and so on. If you actually want to change the state of a window, using wmctrl is an easier tool to use for that.

Although the default list of allowed actions is likely the same for all window managers, you might want to run xprop | grep _NET_WM_ALLOWED_ACTIONS on the window before just to be sure that you're re-setting all of the other actions that were there before. There doesn't seem to be a way of using xprop to remove a single allowed action, only to remove an entire property.

In terms of how foolproof/secure this is, it's probably as good as you can get for a single window. By removing _NET_WM_ACTION_CLOSE or another allowed action, it means that the window is not allowed to receive that action. No matter what method a user might try to close the window, the window will never receive that action. Obviously there are more components to making a secure desktop, but this should be the best way to prevent a window from closing.

However, if the application offers a way of closing itself (e.g. File > Quit), then it will close when that is triggered. Removing _NET_WM_ACTION_CLOSE prevents the action from being received from outside the window, but doesn't prevent the window from triggering the action itself.

share|improve this answer
    
Hi, this isn't working me. I'm using openbox+lxde and the actions I set are _NET_WM_ACTION_CHANGE_DESKTOP, _NET_WM_ACTION_MOVE, _NET_WM_ACTION_MINIMIZE, _NET_WM_ACTION_ABOVE, _NET_WM_ACTION_BELOW. I have no idea why is not working. –  Rho Jan 4 '13 at 16:17
    
@Rho I made a correction to the xprop command (fixed the format from 8s to 32a), see if it works for you now. Also, I'm 100% sure the xprop command was working (with 8s even), but it isn't working for me now under Compiz. I believe when it was working for me I was using metacity (actually Mate's version of metacity). Even under Compiz though, changing _NET_WM_ALLOWED_ACTIONS causes the Taskbar > right click on window to have all of its options grayed out (Minimize, Maximize, Close, etc.), so it's having some effect. –  Animism Jan 17 '13 at 18:06
    
Also, see this SO question and this xprop bug report. According to those, it's not possible to set more than one action using xprop. That matches with what I was seeing under Compiz. That fact that metacity prevented the window from closing might have been because the effect of running the xprop command was to remove all allowed actions from the window. There is a patch in the SO question, so that is worth trying. –  Animism Jan 17 '13 at 18:13

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.