Page 1 of 1

enable/disable minimize/maxinize window buttons

Posted: Sat Jan 22, 2011 12:57 am
by sverson
Does anybody know how to solve this on Linux?

It works fine on Windows...

Code: Select all

Procedure pi_DisableWindowMaximize(WindowNo.i, Disable.i = #True) ; Platform independent DisableWindowMaximize
  Protected WindowID.i
  If IsWindow(WindowNo)
    WindowID = WindowID(WindowNo)
    CompilerSelect #PB_Compiler_OS
      CompilerCase #PB_OS_Windows
        If Disable
          SetWindowLong_(WindowID, #GWL_STYLE, GetWindowLong_(WindowID, #GWL_STYLE) & (#WS_MAXIMIZEBOX ! - 1))
        Else
          SetWindowLong_(WindowID, #GWL_STYLE, GetWindowLong_(WindowID, #GWL_STYLE) | #WS_MAXIMIZEBOX)
        EndIf
        SetWindowPos_(WindowID, 0, 0, 0, 0, 0, #SWP_NOZORDER | #SWP_NOMOVE | #SWP_NOSIZE | #SWP_FRAMECHANGED) 
      CompilerCase #PB_OS_Linux
        ; ToDo - - please help.
        MessageRequester("pi_DisableWindowMaximize","Just works on Windows"+Chr(10)+"Don't know how to code this part. :-((")
      CompilerDefault
        MessageRequester("pi_DisableWindowMaximize","Function not available on this system.")
    CompilerEndSelect
  EndIf
EndProcedure

Procedure pi_DisableWindowMinimize(WindowNo.i, Disable.i = #True) ; Platform independent DisableWindowMinimize
  Protected WindowID.i
  If IsWindow(WindowNo)
    WindowID = WindowID(WindowNo)
    CompilerSelect #PB_Compiler_OS
      CompilerCase #PB_OS_Windows
        If Disable
          SetWindowLong_(WindowID, #GWL_STYLE, GetWindowLong_(WindowID, #GWL_STYLE) & (#WS_MINIMIZEBOX ! - 1))
        Else
          SetWindowLong_(WindowID, #GWL_STYLE, GetWindowLong_(WindowID, #GWL_STYLE) | #WS_MINIMIZEBOX)
        EndIf
        SetWindowPos_(WindowID, 0, 0, 0, 0, 0, #SWP_NOZORDER | #SWP_NOMOVE | #SWP_NOSIZE | #SWP_FRAMECHANGED)
      CompilerCase #PB_OS_Linux
        ; ToDo - - please help.
        MessageRequester("pi_DisableWindowMaximize","Just works on Windows"+Chr(10)+"Don't know how to code this part. :-((")
      CompilerDefault
        MessageRequester("pi_DisableWindowMinimize","Function not available on this system.")
    CompilerEndSelect
  EndIf
EndProcedure

Procedure pi_DisableWindowResize(WindowNo.i, Disable.i = #True) ; Platform independent DisableWindowResize
  Protected WindowID.i
  If IsWindow(WindowNo)
    WindowID = WindowID(WindowNo)
    CompilerSelect #PB_Compiler_OS
      CompilerCase #PB_OS_Windows
        If Disable
          SetWindowLong_(WindowID, #GWL_STYLE, GetWindowLong_(WindowID, #GWL_STYLE) & (#WS_SIZEBOX ! - 1))
        Else
          SetWindowLong_(WindowID, #GWL_STYLE, GetWindowLong_(WindowID, #GWL_STYLE) | #WS_SIZEBOX)
        EndIf
        SetWindowPos_(WindowID, 0, 0, 0, 0, 0, #SWP_NOZORDER | #SWP_NOMOVE | #SWP_NOSIZE | #SWP_FRAMECHANGED)
      CompilerCase #PB_OS_Linux
        ; ToDo - - please help.
        MessageRequester("pi_DisableWindowResize","Just works on Windows"+Chr(10)+"Don't know how to code this part. :-((")
      CompilerDefault
        MessageRequester("pi_DisableWindowResize","Function not available on this system.")
    CompilerEndSelect
  EndIf
EndProcedure

If OpenWindow(0, 0, 0, 200, 200, "Window not resizeable", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_SystemMenu)
  WindowBounds(0, 200, 200, #PB_Ignore, #PB_Ignore)
  ButtonGadget(0, 10, 10, 180, 60, "MinimizeButton")
  ButtonGadget(1, 10, 70, 180, 60, "MaximizeButton")
  ButtonGadget(2, 10, 130, 180, 60, "Sizer")
  
  MyToggle0.i = #False
  MyToggle1.i = #False
  MyToggle2.i = #False
  Repeat
    MyEvent.i = WaitWindowEvent()
    If MyEvent = #PB_Event_Gadget
      Select EventGadget()
        Case 0
          pi_DisableWindowMinimize(0, MyToggle0)
          MyToggle0 ! 1
        Case 1
          pi_DisableWindowMaximize(0, MyToggle1)
          MyToggle1 ! 1
        Case 2
          pi_DisableWindowResize(0, MyToggle2)
          MyToggle2 ! 1
          If MyToggle2
            SetWindowTitle(0, "Window resizeable")
          Else
            SetWindowTitle(0, "Window not resizeable")
            ResizeWindow(0, #PB_Ignore, #PB_Ignore, 200, 200)
          EndIf
      EndSelect
    EndIf
  Until MyEvent = #PB_Event_CloseWindow
EndIf
Thanks. :wink:

Re: enable/disable minimize/maxinize window buttons

Posted: Mon Jan 24, 2011 12:37 pm
by Shardik
Unfortunately I haven't found a way to toggle the Min/Max buttons on a Linux
window on and off and I don't think that this is possible without much effort or
hacks. But enabling/disabling resizing is quite easy. In order for resizing to work
in Linux, WindowBounds() shouldn't be used because this command seems to
effect the resize setting. Therefore I had to prevent the compilation of this
command for Linux...

Code: Select all

Procedure pi_DisableWindowMaximize(WindowNo.i, Disable.i = #True) ; Platform independent DisableWindowMaximize
  Protected WindowID.i
  If IsWindow(WindowNo)
    WindowID = WindowID(WindowNo)
    CompilerSelect #PB_Compiler_OS
      CompilerCase #PB_OS_Windows
        If Disable
          SetWindowLong_(WindowID, #GWL_STYLE, GetWindowLong_(WindowID, #GWL_STYLE) & (#WS_MAXIMIZEBOX ! - 1))
        Else
          SetWindowLong_(WindowID, #GWL_STYLE, GetWindowLong_(WindowID, #GWL_STYLE) | #WS_MAXIMIZEBOX)
        EndIf
        SetWindowPos_(WindowID, 0, 0, 0, 0, 0, #SWP_NOZORDER | #SWP_NOMOVE | #SWP_NOSIZE | #SWP_FRAMECHANGED)
      CompilerCase #PB_OS_Linux
        ; ToDo - - please help.
        MessageRequester("pi_DisableWindowMaximize","Just works on Windows"+Chr(10)+"Don't know how to code this part. :-((")
      CompilerDefault
        MessageRequester("pi_DisableWindowMaximize","Function not available on this system.")
    CompilerEndSelect
  EndIf
EndProcedure

Procedure pi_DisableWindowMinimize(WindowNo.i, Disable.i = #True) ; Platform independent DisableWindowMinimize
  Protected WindowID.i
  If IsWindow(WindowNo)
    WindowID = WindowID(WindowNo)
    CompilerSelect #PB_Compiler_OS
      CompilerCase #PB_OS_Windows
        If Disable
          SetWindowLong_(WindowID, #GWL_STYLE, GetWindowLong_(WindowID, #GWL_STYLE) & (#WS_MINIMIZEBOX ! - 1))
        Else
          SetWindowLong_(WindowID, #GWL_STYLE, GetWindowLong_(WindowID, #GWL_STYLE) | #WS_MINIMIZEBOX)
        EndIf
        SetWindowPos_(WindowID, 0, 0, 0, 0, 0, #SWP_NOZORDER | #SWP_NOMOVE | #SWP_NOSIZE | #SWP_FRAMECHANGED)
      CompilerCase #PB_OS_Linux
        ; ToDo - - please help.
        MessageRequester("pi_DisableWindowMaximize","Just works on Windows"+Chr(10)+"Don't know how to code this part. :-((")
      CompilerDefault
        MessageRequester("pi_DisableWindowMinimize","Function not available on this system.")
    CompilerEndSelect
  EndIf
EndProcedure

Procedure pi_DisableWindowResize(WindowNo.i, Disable.i = #True) ; Platform independent DisableWindowResize
  Protected WindowID.i
  If IsWindow(WindowNo)
    WindowID = WindowID(WindowNo)
    CompilerSelect #PB_Compiler_OS
      CompilerCase #PB_OS_Windows
        If Disable
          SetWindowLong_(WindowID, #GWL_STYLE, GetWindowLong_(WindowID, #GWL_STYLE) & (#WS_SIZEBOX ! - 1))
        Else
          SetWindowLong_(WindowID, #GWL_STYLE, GetWindowLong_(WindowID, #GWL_STYLE) | #WS_SIZEBOX)
        EndIf
        SetWindowPos_(WindowID, 0, 0, 0, 0, 0, #SWP_NOZORDER | #SWP_NOMOVE | #SWP_NOSIZE | #SWP_FRAMECHANGED)
      CompilerCase #PB_OS_Linux
        gtk_window_set_resizable_(WindowID, Disable ! 1)
      CompilerDefault
        MessageRequester("pi_DisableWindowResize","Function not available on this system.")
    CompilerEndSelect
  EndIf
EndProcedure

If OpenWindow(0, 0, 0, 200, 200, "Not resizeable", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_SystemMenu)
  If #PB_Compiler_OS <> #PB_OS_Linux
    WindowBounds(0, 200, 200, #PB_Ignore, #PB_Ignore)
  EndIf

  ButtonGadget(0, 10, 10, 180, 60, "MinimizeButton")
  ButtonGadget(1, 10, 70, 180, 60, "MaximizeButton")
  ButtonGadget(2, 10, 130, 180, 60, "Sizer")
 
  MyToggle0.i = #False
  MyToggle1.i = #False
  MyToggle2.i = #False
  Repeat
    MyEvent.i = WaitWindowEvent()
    If MyEvent = #PB_Event_Gadget
      Select EventGadget()
        Case 0
          pi_DisableWindowMinimize(0, MyToggle0)
          MyToggle0 ! 1
        Case 1
          pi_DisableWindowMaximize(0, MyToggle1)
          MyToggle1 ! 1
        Case 2
          pi_DisableWindowResize(0, MyToggle2)
          MyToggle2 ! 1
          If MyToggle2
            SetWindowTitle(0, "Resizeable")
          Else
            SetWindowTitle(0, "Not resizeable")
            ResizeWindow(0, #PB_Ignore, #PB_Ignore, 200, 200)
          EndIf
      EndSelect
    EndIf
  Until MyEvent = #PB_Event_CloseWindow
EndIf
Update: Sorry, but my statements above seem only to be valid for my
andLinux/Kubuntu 9.04 distribution. The toggling of window resizing does
only work in that distribution, which is a special case because it uses a
modified kernel that runs as a task in Windows. And the displayed window
is an XWindow inside a regular Windows window which always has
Minimize and Maximize buttons and which can't be suppressed.

In Xubuntu 10.04 my above resizing example doesn't work. When trying
to resize, the whole window is always moved.

Sorry for any inconveniance. In Linux it's more difficult because the display
of the titlebar is handled by a window manager which is different in every
distribution and has different policies. Some window managers seem to
allow to switch off single titlebar icons and others don't...

Re: enable/disable minimize/maxinize window buttons

Posted: Mon Jan 24, 2011 11:50 pm
by sverson
Shardik wrote:Update: Sorry, but my statements above seem only to be valid for my
andLinux/Kubuntu 9.04 distribution. The toggling of window resizing does
only work in that distribution, which is a special case because it uses a
modified kernel that runs as a task in Windows. And the displayed window
is an XWindow inside a regular Windows window which always has
Minimize and Maximize buttons and which can't be suppressed.

In Xubuntu 10.04 my above resizing example doesn't work. When trying
to resize, the whole window is always moved.
However, thank you for your efforts.

Re: enable/disable minimize/maxinize window buttons

Posted: Tue Jan 25, 2011 1:58 pm
by Shardik
To test the window displays of different Linux distributions I have used the
following short code example which enables and disables the resizability of
a window:

Code: Select all

OpenWindow(0, 20, 20, 250, 50, "")
ButtonGadget(0, 10, 10, WindowWidth(0) - 20, WindowHeight(0) - 20, "Toggle Resizing")

If gtk_window_get_resizable_(WindowID(0))
  SetWindowTitle(0, "Window is resizable")
Else
  SetWindowTitle(0, "Window is not resizable")
EndIf

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Break
    Case #PB_Event_Gadget
      If EventGadget() = 0
        gtk_window_set_resizable_(WindowID(0), gtk_window_get_resizable_(WindowID(0)) ! 1)

        If gtk_window_get_resizable_(WindowID(0))
          SetWindowTitle(0, "Window is resizable")
        Else
          SetWindowTitle(0, "Window is not resizable")
        EndIf
      EndIf
  EndSelect
ForEver
This is a comparison between 4 Linux distributions in which I tested the
above code in PB 4.51:

andLinux/Kubuntu 9.04 x86
- Close icon is displayed: yes
- Minimize icon is displayed: yes
- Maximize icon is displayed: yes
- Toggle of resizing works: yes (resizing cursor is displayed if the cursor
is above the right bottom edge of the window, although resizing doesn't
work when switched off)

OpenSuse 11.2 x86
- Close icon is displayed: yes
- Minimize icon is displayed: yes
- Maximize icon is displayed: no
- Toggle of resizing works: yes

Suse Linux Enterprise Server 10 SP3 x64
- Close icon is displayed: yes
- Minimize icon is displayed: yes
- Maximize icon is displayed: no
- Toggle of resizing works: yes

Xubuntu 10.04 x86
- Close icon is displayed: yes
- Minimize icon is displayed: no
- Maximize icon is displayed: no
- Toggle of resizing works: no (trying to resize moves the complete window)

This seems to be influenced by the window manager because Xubuntu uses
Xfce and the others KDE. Perhaps somebody with an Ubuntu distribution may
report the results with Gnome...


Update:

Ubuntu 10.04 x86
- Close icon is displayed: yes
- Minimize icon is displayed: no
- Maximize icon is displayed: no
- Toggle of resizing works: yes

So it seems that switching the resizing property of a window is reliably possible
in the two most common window managers KDE and Gnome, but not in Xfce or
maybe some others...