How to remove Close button from window title bar?

Linux specific forum
User avatar
Shardik
Addict
Addict
Posts: 2065
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: How to remove Close button from window title bar?

Post by Shardik »

It depends on the Window Manager of your Linux distribution whether it is possible to remove the close button from a window's title bar with gtk_window_set_deletable():
GTK+ 2 Reference Manual wrote:By default, windows have a close button in the window frame. Some window managers allow GTK+ to disable this button. If you set the deletable property to FALSE using this function, GTK+ will do its best to convince the window manager not to show a close button. Depending on the system, this function may not have any effect when called on a window that is already visible, so you should call it before calling gtk_window_show().
I have tested your modified 1st example below successfully with these Linux distributions (no close button in Window 2):
- ElementaryOS 0.2 x86 with Pantheon
- Fedora 20 x86 with Gnome 3
- Kubuntu 10.04 x86 with KDE
- Kubuntu 14.04 x86 with KDE
- Linux Mint 17 x86 with Cinnamon
- OpenSuse 11.1 x86 with KDE (reported by Vera)
- PearOS 8 x86 with heavily modified Gnome 3
- Xubuntu 14.04 x86 with Xfce (a "+" button is displayed instead of an "x" button in Window 2 but it doesn't close Window 2!)

It doesn't work on these distributions (Close button is still displayed and operational):
- andLinux/Kubuntu 9.04 x86 with KDE (running with a modified CoLinux kernel as task in Windows XP SP3)
- Bodhi Linux 2.4.0 with Enlightenment 17
- Lubuntu 14.04 x86 with LXDE
- Ubuntu 10.04 x86 with Gnome 2
- Ubuntu 14.04 x86 with Unity

Code: Select all

CompilerIf #PB_Compiler_OS = #PB_OS_Linux
  Import ""
    gtk_window_set_deletable(*Window.GtkWindow, Setting.I)
  EndImport
CompilerEndIf

If OpenWindow(0, 0, 0, 320, 240, "Window 1", #PB_Window_ScreenCentered|#PB_Window_SystemMenu)
  If OpenWindow(1, 0, 0, 240, 120, "Window 2", #PB_Window_Tool|#PB_Window_WindowCentered,WindowID(0))
    DisableWindow(0,1)

    CompilerIf #PB_Compiler_OS = #PB_OS_Linux
      gtk_window_set_deletable(WindowID(1), #False)
      gtk_widget_show_(WindowID(1))
    CompilerEndIf

    SetActiveWindow(1)
    ButtonGadget(0, 60, 40, 120, 25, "Close Window 2")
  EndIf
  Repeat
    Event = WaitWindowEvent()
    Select Event
      Case #PB_Event_Gadget
        Select EventGadget()
          Case 0 : CloseWindow(1) : DisableWindow(0,0) : SetActiveWindow(0)
        EndSelect
    EndSelect
  Until Event = #PB_Event_CloseWindow
EndIf

End
Last edited by Shardik on Mon Nov 03, 2014 3:14 pm, edited 3 times in total.
User avatar
Vera
Addict
Addict
Posts: 858
Joined: Tue Aug 11, 2009 1:56 pm
Location: Essen (Germany)

Re: How to remove Close button from window title bar?

Post by Vera »

:) ~ thanks

No x-button showing up on my distro:
- Linux Suse 11.1 x86 with KDE
User avatar
bbanelli
Enthusiast
Enthusiast
Posts: 544
Joined: Tue May 28, 2013 10:51 pm
Location: Europe
Contact:

Re: How to remove Close button from window title bar?

Post by bbanelli »

Shardik wrote:It depends on the Window Manager of your Linux distribution whether it is possible to remove the close button from a window's title bar with gtk_window_set_deletable():
GTK+ 2 Reference Manual wrote:By default, windows have a close button in the window frame. Some window managers allow GTK+ to disable this button. If you set the deletable property to FALSE using this function, GTK+ will do its best to convince the window manager not to show a close button. Depending on the system, this function may not have any effect when called on a window that is already visible, so you should call it before calling gtk_window_show().
Hi Shardik,

thank you once again for very detailed explanation and help!
I have tested your modified 1st example below successfully with these Linux distributions (no close button in Window 2):
- ElementaryOS 0.2 x86 with Pantheon
- Fedora 20 x86 with Gnome 3
- Kubuntu 10.04 x86 with KDE
- Kubuntu 14.04 x86 with KDE
- Linux Mint 17 x86 with Cinnamon
- OpenSuse 11.1 x86 with KDE (reported by Vera)
- PearOS 8 x86 with heavily modified Gnome 3
- Xubuntu 14.04 x86 with Xfce (a "+" button is displayed instead of an "x" button in Window 2 but it doesn't close Window 2!)
It works for me on:
- Ubuntu 12.04 LTS x86 Unity
- Ubuntu 12.04 LTS x86 Gnome
- Ubuntu 12.04 LTS x64 Unity
- Ubuntu 12.04 LTS x64 Gnome


Unity

Code: Select all

bubba@ubuntu-vb:~$ echo $DESKTOP_SESSION
ubuntu-2d
bubba@ubuntu-vb:~$ echo $XDG_CURRENT_DESKTOP
Unity
Gnome

Code: Select all

bubba@ubuntu-vb:~$ echo $DESKTOP_SESSION
gnome-classic
bubba@ubuntu-vb:~$ echo $XDG_CURRENT_DESKTOP
GNOME
Which makes me wonder...
It doesn't work on these distributions (Close button is still displayed and operational):
- Ubuntu 10.04 x86 with Gnome 2
- Ubuntu 14.04 x86 with Unity
Why isn't it working on these two for you?

In any case, perhaps a review of documentation should be in order, since #PB_Window_Tool could have a Linux remark within it?
"If you lie to the compiler, it will get its revenge."
Henry Spencer
https://www.pci-z.com/
User avatar
Shardik
Addict
Addict
Posts: 2065
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: How to remove Close button from window title bar?

Post by Shardik »

bbanelli wrote:It works for me on:
- Ubuntu 12.04 LTS x86 Unity
- Ubuntu 12.04 LTS x86 Gnome
- Ubuntu 12.04 LTS x64 Unity
- Ubuntu 12.04 LTS x64 Gnome
bbanelli wrote:Which makes me wonder...

Code: Select all

It doesn't work on these distributions (Close button is still displayed and operational):
- Ubuntu 10.04 x86 with Gnome 2
- Ubuntu 14.04 x86 with Unity
Why isn't it working on these two for you?
I have also done some tests on Ubuntu 12.04 x86 and it seems to depend on the type of window manager with which you sign on. On my Ubuntu 12.04 x86 installation I have the choice between 4 window managers to use for sign on and it seems that those with 3D features don't allow to remove the close button:
[-] Ubuntu
[+] Ubuntu 2D
[-] GNOME Classic
[+] GNOME Classic (No effects)

In the tests of my previous posting I always used the default window manager for sign on. So for Ubuntu I always used Unity (with 3D features) whereas you used the 2D version... :wink:
User avatar
bbanelli
Enthusiast
Enthusiast
Posts: 544
Joined: Tue May 28, 2013 10:51 pm
Location: Europe
Contact:

Re: How to remove Close button from window title bar?

Post by bbanelli »

Shardik wrote:I have also done some tests on Ubuntu 12.04 x86 and it seems to depend on the type of window manager with which you sign on. On my Ubuntu 12.04 x86 installation I have the choice between 4 window managers to use for sign on and it seems that those with 3D features don't allow to remove the close button:
[-] Ubuntu
[+] Ubuntu 2D
[-] GNOME Classic
[+] GNOME Classic (No effects)

In the tests of my previous posting I always used the default window manager for sign on. So for Ubuntu I always used Unity (with 3D features) whereas you used the 2D version... :wink:
OK, got it for Unity, but GNOME classic works for me on Ubuntu 12.04 LTS x86?!

Image

This really makes me troubled since I plan to publish software and Linux seems to be quite quirky regarding this GTK stuff. I initially thought that this was owing to the PureBasic, but it seems GTK is inconsistent with itself to begin with...
"If you lie to the compiler, it will get its revenge."
Henry Spencer
https://www.pci-z.com/
Post Reply