-2

I'm developing a GUI in Linux (Ubuntu 16.04 - WM: Gnome) using GTK+3 and the graphic library cairo.

After clicked on a push button (Plot), using the instruction of cairo I draw a red square on a new top window where I put a GtkDrawingArea.

In this window I also put a push button (Cancel) that clicked, hide the window. In this way, if I re-push "Plot", the red square reappear.

The issue is the "x" icon present in the top bar of the window. If (no me) a user push this x, the window disapper and if he re-push the "Plot" an error is reported.

The question is: it is possible avoid this possible cause of error? (remove this "x" from the top bar of the window or in some way disable its functionality).

I tryed to find alone a solution and the possibility found are:

1 - Remove from the window the property of "decorated". The top bar disapper (so also the x) but is not possible move the window on the screen

2 - Using the function gtk_window_set_deletable(window, FALSE) (used before to show the window), but the x is always there and pushing it the window is destroyed.

If you think that can be useful, I can report the code. I'm waiting your suggestion.

arkkimede
  • 105
  • 1
  • 12
  • What have you tried to achieve your wanted results? What has your research concerning your problem shown? Can you provide code of your tries? [How do I ask a good question](https://stackoverflow.com/help/how-to-ask), [How much research effort is expected](https://meta.stackoverflow.com/questions/261592/how-much-research-effort-is-expected-of-stack-overflow-users) and [How to create a Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve) might be helpful to improve your question. – Geshode Jan 12 '18 at 12:42
  • You need to tell readers what OS and window manager you're using. [As the documentation clearly states](https://developer.gnome.org/gtk3/stable/GtkWindow.html#gtk-window-set-deletable), GTK+ can only provide hints to the WM to do something; the WM doesn't have to honour the request. Anyway, yes, you should post an MCVE of the code that doesn't hide the close button. _"it does not work"_ alone is not a problem description. – underscore_d Jan 12 '18 at 13:18
  • I reformulated the question and I hope now is more clear – arkkimede Jan 12 '18 at 17:31
  • Thanks, we can now understand what you are trying to achieve. – liberforce Jan 15 '18 at 10:08

1 Answers1

2

Edit:

Now we know what you want to achieve: display a separate window but avoid destroying it so you can display it again. You already have in the "Cancel" button of your secondary window the logic to hide it.

The cleanest solution is to just do the same: when the user tries to close the secondary window, hide it instead. This way the user is not frustrated of seeing something that apparently doesn't work as expected. Hidden or closed, it's different for you but it's the same for the user.

So you just need to connect to the delete-event of that secondary window, and hide it. There's even no need to create a specific callback for that, GTK+ provides it for you: you just need to connect the delete-event to gtk_widget_hide_on_delete. To display the window again, just call gtk_widget_show_all on it.

Original answer:

I realize the plot

"realize" is a term that has a defined meaning in GTK+. Don't use it out of context, and try to use an alternate term if you're not talking about widget realization.

What I would like is to remove this "x" from the top bar of the window or in some way disable its functionality.

Do you understand this is ultra annoying for a user and defeats a unified user experience? Would you like to use applications that do random different things?

Anyway, one way of disabling the closing button is to connect to the delete-event and return TRUE there to stop the propagation of the event. The button will still be there but do nothing, so you will have to kill the app to exit it.

To make the button disappear, gtk_window_set_deletable will ask the Window Manager to do that, but we'd need some code to know what's wrong with your attempt.

liberforce
  • 11,189
  • 37
  • 48
  • 1
    The right way to ask the WM to do this is via `gtk_window_set_deletable`, which they already mentioned, albeit saying vaguely that it doesn't work - and the WM need not honour it anyway. – underscore_d Jan 12 '18 at 13:28
  • liberforce, thank you for your answer. I tryed to reformulate the question and I hope now is easier to understand my requests. In any case Thank You – arkkimede Jan 12 '18 at 17:33
  • Now that you made your question clearer, I am sure you're doing it wrong. Because you were telling us what you wanted to achieve but not why, we couldn't give you the best answer. So I'm editing my post with the One True Way™ of doing that. – liberforce Jan 15 '18 at 10:09