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.