installed pty
[VSoRC/.git] / node_modules / node-pty / deps / winpty / src / shared / BackgroundDesktop.h
1 // Copyright (c) 2011-2016 Ryan Prichard
2 //
3 // Permission is hereby granted, free of charge, to any person obtaining a copy
4 // of this software and associated documentation files (the "Software"), to
5 // deal in the Software without restriction, including without limitation the
6 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7 // sell copies of the Software, and to permit persons to whom the Software is
8 // furnished to do so, subject to the following conditions:
9 //
10 // The above copyright notice and this permission notice shall be included in
11 // all copies or substantial portions of the Software.
12 //
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19 // IN THE SOFTWARE.
20
21 #ifndef WINPTY_SHARED_BACKGROUND_DESKTOP_H
22 #define WINPTY_SHARED_BACKGROUND_DESKTOP_H
23
24 #include <windows.h>
25
26 #include <string>
27
28 #include "WinptyException.h"
29
30 class BackgroundDesktop {
31 public:
32     BackgroundDesktop();
33     ~BackgroundDesktop() { dispose(); }
34     void dispose() WINPTY_NOEXCEPT;
35     const std::wstring &desktopName() const { return m_newDesktopName; }
36
37     BackgroundDesktop(const BackgroundDesktop &other) = delete;
38     BackgroundDesktop &operator=(const BackgroundDesktop &other) = delete;
39
40     // We can't default the move constructor and assignment operator with
41     // MSVC 2013.  We *could* if we required at least MSVC 2015 to build.
42
43     BackgroundDesktop(BackgroundDesktop &&other) :
44             m_originalStation(other.m_originalStation),
45             m_newStation(other.m_newStation),
46             m_newDesktop(other.m_newDesktop),
47             m_newDesktopName(std::move(other.m_newDesktopName)) {
48         other.m_originalStation = nullptr;
49         other.m_newStation = nullptr;
50         other.m_newDesktop = nullptr;
51     }
52     BackgroundDesktop &operator=(BackgroundDesktop &&other) {
53         dispose();
54         m_originalStation = other.m_originalStation;
55         m_newStation = other.m_newStation;
56         m_newDesktop = other.m_newDesktop;
57         m_newDesktopName = std::move(other.m_newDesktopName);
58         other.m_originalStation = nullptr;
59         other.m_newStation = nullptr;
60         other.m_newDesktop = nullptr;
61         return *this;
62     }
63
64 private:
65     HWINSTA m_originalStation = nullptr;
66     HWINSTA m_newStation = nullptr;
67     HDESK m_newDesktop = nullptr;
68     std::wstring m_newDesktopName;
69 };
70
71 std::wstring getCurrentDesktopName();
72
73 #endif // WINPTY_SHARED_BACKGROUND_DESKTOP_H