It is currently Wed Jan 27, 2021 7:43 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: Is it possible to hide the window Close Button?
PostPosted: Thu May 14, 2020 5:33 pm 
Offline
Enthusiast
Enthusiast

Joined: Thu May 21, 2009 6:56 pm
Posts: 599
Hi

I have single windowed application that should never be closed so I would like to remove the "Close" button from the Window's title bar. Is that possible and if so how?

Thanks,
Simon

_________________
Simon White
dCipher Computing


Top
 Profile  
Reply with quote  
 Post subject: Re: Is it possible to hide the window Close Button?
PostPosted: Thu May 14, 2020 5:48 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sat Oct 06, 2007 11:20 pm
Posts: 298
Location: France
Hi,
Don't use #PB_Window_SystemMenu as openwindows flag

Code:
If OpenWindow(0, 0, 0, 220, 100, "Exemple...", #PB_Window_ScreenCentered)

   ButtonGadget  (1, 10, 60, 200, 30, "Exit")
   
   Repeat
     Event = WaitWindowEvent()
     
     Select Event
         
       Case #PB_Event_Gadget
         Select EventGadget()
           Case 1
              Ex = 1
         EndSelect
           
     EndSelect
   Until EX = 1
 EndIf

End 

_________________
~Ar-S~

My webSite (french) with PB apps : LDVMULTIMEDIA
PB - 5.4x LTS / 5.7x - W10 x64 - Ryzen 7 3700x
Repeat : try : until done = 1


Top
 Profile  
Reply with quote  
 Post subject: Re: Is it possible to hide the window Close Button?
PostPosted: Fri May 15, 2020 12:52 am 
Offline
Enthusiast
Enthusiast

Joined: Thu May 21, 2009 6:56 pm
Posts: 599
Hi

That works fine in Windows but I still have the close button in Linux.

Simon

_________________
Simon White
dCipher Computing


Top
 Profile  
Reply with quote  
 Post subject: Re: Is it possible to hide the window Close Button?
PostPosted: Fri May 15, 2020 10:14 am 
Offline
Addict
Addict
User avatar

Joined: Thu Apr 21, 2005 2:38 pm
Posts: 1791
Location: Germany
Have you already read this posting and tried the example?


Top
 Profile  
Reply with quote  
 Post subject: Re: Is it possible to hide the window Close Button?
PostPosted: Fri May 15, 2020 2:48 pm 
Offline
Enthusiast
Enthusiast

Joined: Thu May 21, 2009 6:56 pm
Posts: 599
Hi

I had not read the post you suggested but have done so now and the close button is removed. However I have the Minimize and Maximize buttons showing which was not the case before I tried you code. So I would like to remove the Close, Minimize and Maximize buttons.

Thanks,
Simon

_________________
Simon White
dCipher Computing


Top
 Profile  
Reply with quote  
 Post subject: Re: Is it possible to hide the window Close Button?
PostPosted: Fri May 29, 2020 6:22 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Apr 21, 2005 2:38 pm
Posts: 1791
Location: Germany
swhite wrote:
However I have the Minimize and Maximize buttons showing which was not the case before I tried you code.

To help you any further it is essential to know your Linux distribution and your desktop environment because - as I have already remarked in my linked posting above - it depends on your desktop environment and window manager whether they allow manipulations of the titlebar. My posted example works fine in Linux Mint 19.3 'Tricia' with Cinnamon and doesn't display minimize and maximize buttons. Other window managers like Gnome 3, Xfce or LXDE do indeed display them together with the close symbol which may be removed.

swhite wrote:
So I would like to remove the Close, Minimize and Maximize buttons.

I don't have found a direct way to also remove the minimize and maximize buttons. But you may do another trick by overwriting your window's titlebar with a GtkHeaderBar containing only the window title. In this case GTK is in command and not the window manager of your distribution. The disadvantage is a title bar with an increased height because the GtkHeaderBar is a container which also may display a subtitle or other GTK widgets (of course also the minimize, maximize and close buttons). You may try the following example which only displays a centered title text. I tested it successfully on these distributions:
  • Linux Mint 19.3 x64 with Cinnamon (PB 5.46 x64 in ASCII and Unicode mode and PB 5.72 x64)
  • Lubuntu 18.04 x86 with LXDE (PB 5.46 x86 in ASCII and Unicode mode and PB 5.72 x86)
  • Ubuntu 18.04 x86 with Gnome 3 (PB 5.46 x86 in ASCII and Unicode mode and PB 5.72 x86)
  • Ubuntu MATE 18.04 x86 with MATE (PB 5.46 x86 in ASCII and Unicode mode and PB 5.72 x86)
  • Xubuntu 18.04 x86 with Xfce (PB 5.46 x86 in ASCII and Unicode mode and PB 5.72 x86)
Code:
EnableExplicit

#HeaderBarTitle = "Close window with <Esc> key"

Import ""
  gtk_header_bar_new()
  gtk_header_bar_set_title(*HeaderBar, *Title)
  gtk_window_set_titlebar(*Window.GtkWindow, *TitleBar.GtkWidget)
EndImport

Define HeaderBar.I
Define HeaderBarTitle.S = Space(StringByteLength(#HeaderBarTitle) + SizeOf(Integer))
Define WindowHeight.I
Define WindowWidth.I
Define WindowX.I
Define WindowY.I

OpenWindow(0, 100, 100, 320, 120, "Window with closing button",
  #PB_Window_SystemMenu | #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget)
ButtonGadget(0, 58, 40, 200, 25, "Remove all titlebar buttons")
AddKeyboardShortcut(0, #PB_Shortcut_Escape, 0)

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Break
    Case #PB_Event_Menu
      If EventMenu() = 0
        Break
      EndIf
    Case #PB_Event_Gadget
      If EventGadget() = 0
        WindowX = WindowX(0)
        WindowY = WindowY(0)
        WindowHeight = WindowHeight(0)
        WindowWidth = WindowWidth(0)
        HeaderBar = gtk_header_bar_new()
        PokeS(@HeaderBarTitle, #HeaderBarTitle, -1, #PB_UTF8)
        gtk_header_bar_set_title(HeaderBar, @HeaderBarTitle)
        gtk_window_set_titlebar(WindowID(0), HeaderBar)
        ResizeWindow(0, WindowX, WindowY, WindowWidth, WindowHeight)
        gtk_widget_show_all_(WindowID(0))
        DisableGadget(0, #True)
        SetActiveWindow(0)
      EndIf
  EndSelect
ForEver


Top
 Profile  
Reply with quote  
 Post subject: Re: Is it possible to hide the window Close Button?
PostPosted: Sat May 30, 2020 4:00 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Apr 21, 2005 2:38 pm
Posts: 1791
Location: Germany
I have modified my example from above to reduce the new titlebar's height (GtkHeaderBar) to that of PB's default titlebar height:
Code:
EnableExplicit

#HeaderBarTitle = "Close window with <Esc> key"

#GTK_STYLE_PROVIDER_PRIORITY_APPLICATION = 600

ImportC ""
  gtk_css_provider_load_from_data (*CSSProvider, *CSSData, CSSDataLength.I,
    *Error.GError)
  gtk_css_provider_new()
  gtk_style_context_add_provider_for_screen(*Screen.GdkScreen, *StyleProvider,
    Priority.I)
  gtk_header_bar_new()
  gtk_header_bar_set_has_subtitle(*HeaderBar, Setting.L)
  gtk_header_bar_set_title(*HeaderBar, Title.P-UTF8)
  gtk_window_set_titlebar(*Window.GtkWindow, *TitleBar.GtkWidget)
EndImport

Define CSSProvider.I
Define *CSSStyle
Define Error.GError
Define HeaderBar.I
Define Screen.I
Define TitlebarHeight.I
Define WindowHeight.I
Define WindowWidth.I
Define WindowX.I
Define WindowY.I

OpenWindow(0, 100, 100, 320, 120, "Window with closing button",
  #PB_Window_SystemMenu | #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget)
ButtonGadget(0, 58, 40, 200, 25, "Remove all titlebar buttons")
AddKeyboardShortcut(0, #PB_Shortcut_Escape, 0)

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Break
    Case #PB_Event_Menu
      If EventMenu() = 0
        Break
      EndIf
    Case #PB_Event_Gadget
      If EventGadget() = 0
        WindowX = WindowX(0)
        WindowY = WindowY(0)
        WindowHeight = WindowHeight(0)
        WindowWidth = WindowWidth(0)
        TitlebarHeight = WindowHeight(0, #PB_Window_FrameCoordinate) +
          0 - WindowHeight(0, #PB_Window_InnerCoordinate) - 2

        ; ----- Replace titlebar with GtkHeaderBar
        HeaderBar = gtk_header_bar_new()
        gtk_header_bar_set_has_subtitle(HeaderBar, #False)
        gtk_header_bar_set_title(HeaderBar, #HeaderBarTitle)
        gtk_window_set_titlebar(WindowID(0), HeaderBar)
        ResizeWindow(0, WindowX, WindowY, WindowWidth, WindowHeight)

        ; ----- Reduce height of HeaderBar
        CSSProvider = gtk_css_provider_new()
        *CSSStyle = UTF8("headerbar {min-height: " + Str(TitlebarHeight) +
          "px;}")
        gtk_css_provider_load_from_data(CSSProvider, *CSSStyle,
          MemorySize(*CSSStyle), @Error)
        Screen = gdk_display_get_default_screen_(gdk_display_get_default_())
        gtk_style_context_add_provider_for_screen(Screen, CSSProvider,
          #GTK_STYLE_PROVIDER_PRIORITY_APPLICATION)
        g_object_unref_(CSSProvider)
        FreeMemory(*CSSStyle)

        ; ----- Display modified window
        gtk_widget_show_all_(WindowID(0))
        DisableGadget(0, #True)
        SetActiveWindow(0)
      EndIf
  EndSelect
ForEver


Top
 Profile  
Reply with quote  
 Post subject: Re: Is it possible to hide the window Close Button?
PostPosted: Mon Jun 01, 2020 2:11 pm 
Offline
Enthusiast
Enthusiast

Joined: Thu May 21, 2009 6:56 pm
Posts: 599
Hi

I am running XFCE on OpenSuse 15.1 with PB 5.72 64bit.

Simon

_________________
Simon White
dCipher Computing


Top
 Profile  
Reply with quote  
 Post subject: Re: Is it possible to hide the window Close Button?
PostPosted: Mon Jun 01, 2020 5:40 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Apr 21, 2005 2:38 pm
Posts: 1791
Location: Germany
swhite wrote:
I am running XFCE on OpenSuse 15.1 with PB 5.72 64bit.

Thank you. But have you tried my last two examples? Theoretically they should run on all Linux distributions because they are not dependant on the window manager of your distribution anymore...


Top
 Profile  
Reply with quote  
 Post subject: Re: Is it possible to hide the window Close Button?
PostPosted: Mon Jun 01, 2020 7:41 pm 
Offline
Enthusiast
Enthusiast

Joined: Thu May 21, 2009 6:56 pm
Posts: 599
Hi

Yes they both work perfectly.

Thanks,
Simon

_________________
Simon White
dCipher Computing


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye