private void ShowHideBars(AppBarNativeWindow previousAppBarTopWindow, AppBarNativeWindow previousAppBarBottomWindow, AppBarNativeWindow newAppBarTopWindow, AppBarNativeWindow newAppBarBottomWindow, Workspace oldWorkspace, Workspace newWorkspace) { ShowHideAppBarForms(previousAppBarTopWindow, newAppBarTopWindow); ShowHideAppBarForms(previousAppBarBottomWindow, newAppBarBottomWindow); var oldBarsAtTop = oldWorkspace.barsAtTop[monitorIndex]; var oldBarsAtBottom = oldWorkspace.barsAtBottom[monitorIndex]; var newBarsAtTop = newWorkspace.barsAtTop[monitorIndex]; var newBarsAtBottom = newWorkspace.barsAtBottom[monitorIndex]; // first position and show new bars var winPosInfo = NativeMethods.BeginDeferWindowPos(newBarsAtTop.Count + newBarsAtBottom.Count); if (newAppBarTopWindow != null) { winPosInfo = newAppBarTopWindow.PositionBars(winPosInfo, newBarsAtTop); } if (newAppBarBottomWindow != null) { winPosInfo = newAppBarBottomWindow.PositionBars(winPosInfo, newBarsAtBottom); } NativeMethods.EndDeferWindowPos(winPosInfo); newBarsAtTop.Concat(newBarsAtBottom).ForEach(b => b.Show()); // and only after that hide the old ones to avoid flickering oldBarsAtTop.Concat(oldBarsAtBottom).Except(newBarsAtTop.Concat(newBarsAtBottom)).ForEach(b => b.Hide()); }
internal void AddWorkspace(Workspace workspace) { var workspaceBarsAtTop = workspace.barsAtTop[monitorIndex]; var workspaceBarsAtBottom = workspace.barsAtBottom[monitorIndex]; var matchingBar = workspaces.Keys.FirstOrDefault(ws => workspaceBarsAtTop.SequenceEqual(ws.barsAtTop[monitorIndex]) && workspaceBarsAtBottom.SequenceEqual(ws.barsAtBottom[monitorIndex])); if (matchingBar != null) { var matchingWorkspace = workspaces[matchingBar]; this.workspaces[workspace] = Tuple.Create(matchingWorkspace.Item1, matchingWorkspace.Item2, matchingWorkspace.Item3); return; } var workspaceBarsEquivalentClass = (this.workspaces.Count == 0 ? 0 : this.workspaces.Values.Max(t => t.Item1)) + 1; AppBarNativeWindow appBarTopWindow; var topBarsHeight = workspaceBarsAtTop.Sum(bar => bar.GetBarHeight()); var matchingAppBar = workspaces.Values.Select(t => t.Item2).FirstOrDefault(ab => (ab == null && topBarsHeight == 0) || (ab != null && topBarsHeight == ab.height)); if (matchingAppBar != null || topBarsHeight == 0) { appBarTopWindow = matchingAppBar; } else { appBarTopWindow = new AppBarNativeWindow(topBarsHeight, true); } AppBarNativeWindow appBarBottomWindow; var bottomBarsHeight = workspaceBarsAtBottom.Sum(bar => bar.GetBarHeight()); matchingAppBar = workspaces.Values.Select(t => t.Item3).FirstOrDefault(uniqueAppBar => (uniqueAppBar == null && bottomBarsHeight == 0) || (uniqueAppBar != null && bottomBarsHeight == uniqueAppBar.height)); if (matchingAppBar != null || bottomBarsHeight == 0) { appBarBottomWindow = matchingAppBar; } else { appBarBottomWindow = new AppBarNativeWindow(bottomBarsHeight, false); } this.workspaces[workspace] = Tuple.Create(workspaceBarsEquivalentClass, appBarTopWindow, appBarBottomWindow); }
private void ShowHideAppBarForms(AppBarNativeWindow hideForm, AppBarNativeWindow showForm) { // this whole thing is so complicated as to avoid changing of the working area if the bars in the new workspace // take the same space as the one in the previous one // set the working area to a new one if needed if (hideForm != null) { if (showForm == null || hideForm != showForm) { hideForm.Hide(); if (showForm != null) { showForm.SetPosition(this); } } } else if (showForm != null) { showForm.SetPosition(this); } }
private void ShowHideAppBarsAndRepositionBars(AppBarNativeWindow previousAppBarTopWindow, AppBarNativeWindow previousAppBarBottomWindow, AppBarNativeWindow newAppBarTopWindow, AppBarNativeWindow newAppBarBottomWindow, Workspace newWorkspace) { ShowHideAppBarForms(previousAppBarTopWindow, newAppBarTopWindow); ShowHideAppBarForms(previousAppBarBottomWindow, newAppBarBottomWindow); var newBarsAtTop = newWorkspace.barsAtTop[monitorIndex]; var newBarsAtBottom = newWorkspace.barsAtBottom[monitorIndex]; var winPosInfo = NativeMethods.BeginDeferWindowPos(newBarsAtTop.Count + newBarsAtBottom.Count); if (newAppBarTopWindow != null) { winPosInfo = newAppBarTopWindow.PositionBars(winPosInfo, newBarsAtTop); } if (newAppBarBottomWindow != null) { winPosInfo = newAppBarBottomWindow.PositionBars(winPosInfo, newBarsAtBottom); } NativeMethods.EndDeferWindowPos(winPosInfo); }
internal void AddWorkspace(Workspace workspace) { var workspaceBarsAtTop = workspace.barsAtTop[monitorIndex]; var workspaceBarsAtBottom = workspace.barsAtBottom[monitorIndex]; var matchingBar = workspaces.Keys.FirstOrDefault(ws => workspaceBarsAtTop.SequenceEqual(ws.barsAtTop[monitorIndex]) && workspaceBarsAtBottom.SequenceEqual(ws.barsAtBottom[monitorIndex])); if (matchingBar != null) { var matchingWorkspace = workspaces[matchingBar]; this.workspaces[workspace] = Tuple.Create(matchingWorkspace.Item1, matchingWorkspace.Item2, matchingWorkspace.Item3); return ; } var workspaceBarsEquivalentClass = (this.workspaces.Count == 0 ? 0 : this.workspaces.Values.Max(t => t.Item1)) + 1; AppBarNativeWindow appBarTopWindow; var topBarsHeight = workspaceBarsAtTop.Sum(bar => bar.GetBarHeight()); var matchingAppBar = workspaces.Values.Select(t => t.Item2).FirstOrDefault(ab => (ab == null && topBarsHeight == 0) || (ab != null && topBarsHeight == ab.height)); if (matchingAppBar != null || topBarsHeight == 0) { appBarTopWindow = matchingAppBar; } else { appBarTopWindow = new AppBarNativeWindow(topBarsHeight, true); } AppBarNativeWindow appBarBottomWindow; var bottomBarsHeight = workspaceBarsAtBottom.Sum(bar => bar.GetBarHeight()); matchingAppBar = workspaces.Values.Select(t => t.Item3).FirstOrDefault(uniqueAppBar => (uniqueAppBar == null && bottomBarsHeight == 0) || (uniqueAppBar != null && bottomBarsHeight == uniqueAppBar.height)); if (matchingAppBar != null || bottomBarsHeight == 0) { appBarBottomWindow = matchingAppBar; } else { appBarBottomWindow = new AppBarNativeWindow(bottomBarsHeight, false); } this.workspaces[workspace] = Tuple.Create(workspaceBarsEquivalentClass, appBarTopWindow, appBarBottomWindow); }