Query windows information

Hello

In a plugin we display various views on different screens:

Dictionary<FQID, FQID> _screens = new Dictionary<FQID, FQID>();
 
private void ShowView(Item screen, Item view)
{
    var windows = Configuration.Instance.GetItemsByKind(Kind.Window);
 
    if (!_screens.ContainsKey(screen.FQID) || !windows.Any(w => w.FQID.ObjectId == _screens[screen.FQID].ObjectId))
    {
        var openFullScreenData = new MultiWindowCommandData();
        openFullScreenData.MultiWindowCommand = MultiWindowCommand.OpenFullScreenWindow;
        openFullScreenData.Screen = screen.FQID;
        openFullScreenData.Window = windows[0].FQID;
        openFullScreenData.View = view.FQID;
        var objects = SendMessageOnUiThread(new Message(MessageId.SmartClient.MultiWindowCommand, openFullScreenData));
        _screens[screen.FQID] = objects[0] as FQID;
    }
 
    var windowFQID = _screens[screen.FQID];
 
    var setViewInWindowData = new MultiWindowCommandData();
    setViewInWindowData.MultiWindowCommand = MultiWindowCommand.SetViewInWindow;
    setViewInWindowData.Screen = screen.FQID;
    setViewInWindowData.Window = windowFQID;
    setViewInWindowData.View = view.FQID;
    SendMessageOnUiThread(new Message(MessageId.SmartClient.MultiWindowCommand, setViewInWindowData));
 
    var selectWindowData = new MultiWindowCommandData();
    selectWindowData.MultiWindowCommand = MultiWindowCommand.SelectWindow;
    selectWindowData.Screen = screen.FQID;
    selectWindowData.Window = windowFQID;
    selectWindowData.View = view.FQID;
    SendMessageOnUiThread(new Message(MessageId.SmartClient.MultiWindowCommand, selectWindowData));
 
    var moveCommandData = new SetSelectedViewItemData() { MoveCommand = MoveCommand.Deselect };
    SendMessageOnUiThread(new Message(MessageId.SmartClient.SetSelectedViewItemCommand, moveCommandData));
}
 
private System.Collections.ObjectModel.Collection<object> SendMessageOnUiThread(VideoOS.Platform.Messaging.Message message)
{
    System.Collections.ObjectModel.Collection<object> objects = null;
    ClientControl.Instance.CallOnUiThread(() => { objects = EnvironmentManager.Instance.SendMessage(message); });
    return objects;
}

For me this is the only way to figure out which windows is display on which screen (by keeping track of it after its creation).

It looks like when you do Configuration.Instance.GetItemsByKind(Kind.Window), you only can know about it’s size and position but you don’t have access to its name (only “Floating window”) nor can you figure out which view is displayed on it.

I find it very weird that with GetItemsByKind() you can have a List for screens, a List for windows, and no way of knowing which maps to which, when obviously a window is only displayed on one screen.

So here is my question: is there a better way?

Bonus question: do you know why these two FQID are different? One is the one returned by SendMessage(), the other is the one returned by GetItemsByKind()

windows[1].FQID
 
{Server:SC:localhost Id:00000000-0000-0000-0000-000000000000, ObjectId:0d7925ea-4ea2-4162-9079-678a1c519b9e, Type:15da80d4-7595-431f-9866-674d2b80acc5}
  FolderType: No
  Kind: {15da80d4-7595-431f-9866-674d2b80acc5}
  ObjectId: {0d7925ea-4ea2-4162-9079-678a1c519b9e}
  ObjectIdString: null
  ParentId: {00000000-0000-0000-0000-000000000000}
  ServerId: {VideoOS.Platform.ServerId}
 
_screens[screen.FQID]
 
{Server:SC:localhost Id:00000000-0000-0000-0000-000000000000, ObjectId:0d7925ea-4ea2-4162-9079-678a1c519b9e, Type:15da80d4-7595-431f-9866-674d2b80acc5}
  FolderType: No
  Kind: {15da80d4-7595-431f-9866-674d2b80acc5}
  ObjectId: {0d7925ea-4ea2-4162-9079-678a1c519b9e}
  ObjectIdString: null
  ParentId: {00000000-0000-0000-0000-000000000000}
  ServerId: {VideoOS.Platform.ServerId}
 
_screens[screen.FQID] == windows[1].FQID
 
false
 
_screens[screen.FQID].ObjectId == windows[1].FQID.ObjectId
 
true

We are aware that currently the screen/window/view associations are not easy to work with, but unfortunately we have not yet had the time to improve this, so unfortunately your method is as good as it gets.

As to the bonus question, the answer is simply that we hadn’t overwritten the == operator and thus the object references are compared. We will make sure to do this for the next release. Current work-around is to use .Equals instead of == (as the Equals method has an override).

Thanks. I really hope you improve the windowing API because it’s annoying to have to close all windows at startup just to be able to recreate them again in order to know which one is which one.

By the way, is there an event to know when the smart client is “ready” to process messages?

If I EnvironmentManager.Instance.SendMessage() a MultiWindowCommand.CloseAllWindows in Init() the message is not sent (the previous windows are not closed). If I wait like ~5 secondes then it’s ok. I know I could setup the Smart Client option to not restore windows on boot but that’s plan B :slight_smile:

If you listen and wait for SmartClient.WorkSpaceReadyIndication you should be good.

Thanks a lot!