[Solved] Linux Workspace 2-4

Post your Gambas programming questions here.
AndyGable
Posts: 359
Joined: Wednesday 2nd December 2020 12:11am
Location: Northampton, England
Contact:

[Solved] Linux Workspace 2-4

Post by AndyGable »

Hi Everyone

Is it possible to have a application start on Workspace 1 but move it to another workspace ?

For example my main workspace (workspace 1 on Debian) is where I work on my code but when the app starts i would like it to show in Workspace 2 (the 4 little boxes at the bottom of the screen in Debian linux)

The Idea is I want to load some background apps but have thier windows display on other workspace and keep the main workspace clear

can I do this with Gambas or do I have to load each program I want in each workspace?
Last edited by AndyGable on Tuesday 25th April 2023 12:23am, edited 1 time in total.
User avatar
BruceSteers
Posts: 1521
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Linux Workspace 2-4

Post by BruceSteers »

I believe you can use Form.Move()

The workspaces are calculated as one big desktop.
So to open the form at x ,y position 100, 100 on a workspace to the right of the main screen do this...
MyForm.Move(Screen.Width + 100, 100)
MyForm.Show
If at first you don't succeed , try doing something differently.
BruceS
User avatar
BruceSteers
Posts: 1521
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Linux Workspace 2-4

Post by BruceSteers »

BruceSteers wrote: Wednesday 19th October 2022 8:36pm I believe you can use Form.Move()

The workspaces are calculated as one big desktop.
So to open the form at x ,y position 100, 100 on a workspace to the right of the main screen do this...
MyForm.Move(Screen.Width + 100, 100)
MyForm.Show
Darn my apologies, that does not seem to work :(

I read this reply from Benoit on stack overflow https://stackoverflow.com/questions/538 ... ond-screen
Although he is talking about screens there not virtual desktops.
If at first you don't succeed , try doing something differently.
BruceS
User avatar
BruceSteers
Posts: 1521
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Linux Workspace 2-4

Post by BruceSteers »

I found a way that works...

this way moves the current active window to workspace to the right of the current one.
  X11.MoveWindow(X11.ActiveWindow, Screen.W + 100, Me.Top)
Or this for a specific window...

Public Sub btn2_Click()

  Form2.Show
  Dim iActiv As Integer = X11.ActiveWindow ' for some reason if you do not use this line the next line crashes gambas

  X11.MoveWindow(Form2.Id, Screen.W + Form2.X, form2.Top)

End



Requires the gb.desktop.x11 component
Last edited by BruceSteers on Saturday 22nd October 2022 12:21pm, edited 1 time in total.
If at first you don't succeed , try doing something differently.
BruceS
User avatar
BruceSteers
Posts: 1521
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Linux Workspace 2-4

Post by BruceSteers »

Also this works... (also needs gb.desktop.x11)
Public Sub btnMoveWindowToRightWorkspace_Click()

  Form2.Show
  Dim dw As DesktopWindow = New DesktopWindow(Form2.Id)
  if Desktop.Type = "MATE" Then dw.Move(Screen.W + Form2.X, Form2.Top) Else dw.Desktop +=1

End


and note. this will most definitely NOT work on wayland, it's x11 only.
If at first you don't succeed , try doing something differently.
BruceS
User avatar
BruceSteers
Posts: 1521
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Linux Workspace 2-4

Post by BruceSteers »

This has been interesting.

I made a class file..
It's in my project .src called Form.class

EDITED:
' Gambas class file
' with file name Form.class in your .src folder this adds workspace shifting to ALL Forms
' Requires gb.desktop.x11

Create Static
Export

Public Enum Move_Left, Move_Right, Move_Up, Move_Down

Public Sub MoveToWorkSpace((Direction) As Integer, Optional Follow As Boolean)

  Dim xw As DesktopWindow = New DesktopWindow(Me.Handle)

  Select Direction

    Case Move_Right
      If Desktop.Type = "MATE" Then xw.Move(Screen.Width + Me.X, Me.Top) Else xw.Desktop += 1

    Case Move_Left
      If Desktop.Type = "MATE" Then xw.Move(0 - Screen.Width + Me.X, Me.Top) Else xw.Desktop = Max(xw.Desktop - 1, 0)
    ' Note, setting Desktop to -1 makes the window sticky (shows on all workspaces) so we limit to 0

  End Select

   If Follow Then
    If Desktop.Type = "MATE" Then
      Me.Activate
    Else
      X11.CurrentDesktop = If(Direction = Move_Right, X11.CurrentDesktop + 1, Max(X11.CurrentDesktop - 1, 0))
    Endif
  Endif

End

This saved as Form.class adds workspace switching to all and any of my Forms :)

So my app can now do this with menu items to shift the window left or right...

Public Sub mnuWorkspaceLeft_Click()

  FMain.MoveToWorkSpace(Form.Move_Left, True)

End

Public Sub mnuWorkspaceRight_Click()

  FMain.MoveToWorkSpace(Form.Move_Right, True)

End
PS. the Follow boolean option toggles between moving a window to a workspace and staying on the current workspace or switching workspace with it.
If at first you don't succeed , try doing something differently.
BruceS
User avatar
BruceSteers
Posts: 1521
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Linux Workspace 2-4

Post by BruceSteers »

I tested this on other desktops like gnome and cinnamon and find it does not really work on anything except MATE desktop.
:(

this was because i found setting the X11.DesktopWindow.Desktop property did not make the window switch workspace ,, on MATE , but turns out it does on gnome and cinnamon.

So i have modified the above code to make moving left or right work on the other desktops.
making up and down work involves a bit more code and getting info about the layout that i have not got working yet.
If at first you don't succeed , try doing something differently.
BruceS
User avatar
grayghost4
Posts: 174
Joined: Wednesday 5th December 2018 5:00am
Location: Marengo, Illinois usa

Re: Linux Workspace 2-4

Post by grayghost4 »

I have tried it in KDE and the window moves but is not visible on the new desktop. :x

I have not tried the new code.... yet.

new code makes it work :D

but it does not follow .
User avatar
grayghost4
Posts: 174
Joined: Wednesday 5th December 2018 5:00am
Location: Marengo, Illinois usa

Re: Linux Workspace 2-4

Post by grayghost4 »

it will only move if there is already a desktop open in the direction of the move ... it does not create a desktop.

And it will follow if there is an open program on the new desktop.
User avatar
cogier
Site Admin
Posts: 1118
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: Linux Workspace 2-4

Post by cogier »

I use Linux Mint 20.3 with the Cinnamon desktop.

I could not get Gambas to do what was wanted, so I took a different tack. I have no idea if it will work in your distro, but here are my efforts.



Image

Run the following code in a Graphical Application
' Gambas class file

CheckBox1 As CheckBox
$iCurrentWS As Integer      'Stores the current workspace
AllButtons As New Button[]  'Keeps an array of all the Buttons

Public Sub Form_Open()

  Dim iGet As Integer[] = GetWorkSpaces()

  $iCurrentWS = iGet[1]
  BuildForm
  SetCurrentButton

End

Public Sub Buttons_Click() 'Triggered when any of the buttons are clicked

  MoveToWorkspace(Last.Tag, CheckBox1.Value)
  $iCurrentWS = Last.Tag
  SetCurrentButton

End

Public Sub SetCurrentButton() 'This disables the current workspace button

  Action["Enable"].Enabled = True
  AllButtons[$iCurrentWS].Enabled = False

End

Public Sub MoveToWorkspace(Workspace As Integer, Optional DontFollow As Boolean) 'This moves the program

  If DontFollow = True Then
    Shell "wmctrl -r :ACTIVE: -t " & Str(Workspace)
  Else
    Shell "wmctrl -r :ACTIVE: -t " & Str(Workspace) & "; wmctrl -s " & Str(Workspace)
  Endif

End

Public Sub GetWorkSpaces() As Integer[] 'This gets the number of Workspaces available

  Dim sWPlaces As String
  Dim sWorkPlaces As String[]
  Dim iLoop, iCurrent As Integer

  Shell "wmctrl -d" To sWPlaces
  sWorkPlaces = Split(sWPlaces, gb.newline, "", True)

  For iLoop = 0 To sWorkPlaces.Max
    If InStr(sWorkPlaces[iLoop], "*") > 0 Then iCurrent = iLoop
  Next

  Return [sWorkPlaces.Max, iCurrent]

End

Public Sub BuildForm() 'This puts all the objects needed on the form

  Dim hButton As Button
  Dim VBox1 As VBox
  Dim pPanel As Panel
  Dim iLoop As Integer
  Dim iGet As Integer[] = GetWorkSpaces()
  Dim sWS As Integer = iGet[0]

  With Me
    .Height = 400
    .Width = 200
    .Padding = 5
    .Arrangement = Arrange.Vertical
    .Title = "Move me!"
    .Center
  End With

  With VBox1 = New VBox(Me) As "VBox1"
    .height = 300
    .Width = 100
    .Expand = True
  End With

  With CheckBox1 = New CheckBox(VBox1) As "CheckBox1"
    .Text = "Don't follow me."
    .ToolTip = "If checked the program will move by you wont!"
    .Value = False
  End With

  For iLoop = 0 To sWs
    With pPanel = New Panel(VBox1)
      .Height = 7
    End With
    With hButton = New Button(VBox1) As "Buttons"
      .Height = 28
      .Width = 100
      .Text = "Move me to Workspace " & Str(iLoop)
      .Tag = iLoop
      .Action = "Enable"
    End With
    AllButtons.Add(hButton)
  Next

End
Post Reply