Page 1 of 1

Is it possible to hide the window Close Button?

Posted: Thu May 14, 2020 5:33 pm
by swhite
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

Re: Is it possible to hide the window Close Button?

Posted: Thu May 14, 2020 5:48 pm
by ar-s
Hi,
Don't use #PB_Window_SystemMenu as openwindows flag

Code: Select all

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  

Re: Is it possible to hide the window Close Button?

Posted: Fri May 15, 2020 12:52 am
by swhite
Hi

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

Simon

Re: Is it possible to hide the window Close Button?

Posted: Fri May 15, 2020 10:14 am
by Shardik
Have you already read this posting and tried the example?

Re: Is it possible to hide the window Close Button?

Posted: Fri May 15, 2020 2:48 pm
by swhite
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

Re: Is it possible to hide the window Close Button?

Posted: Fri May 29, 2020 6:22 pm
by Shardik
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: Select all

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

Re: Is it possible to hide the window Close Button?

Posted: Sat May 30, 2020 4:00 pm
by Shardik
I have modified my example from above to reduce the new titlebar's height (GtkHeaderBar) to that of PB's default titlebar height:

Code: Select all

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

Re: Is it possible to hide the window Close Button?

Posted: Mon Jun 01, 2020 2:11 pm
by swhite
Hi

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

Simon

Re: Is it possible to hide the window Close Button?

Posted: Mon Jun 01, 2020 5:40 pm
by Shardik
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...

Re: Is it possible to hide the window Close Button?

Posted: Mon Jun 01, 2020 7:41 pm
by swhite
Hi

Yes they both work perfectly.

Thanks,
Simon