KiCad PCB EDA Suite
Loading...
Searching...
No Matches
gtk/environment.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2020 Ian McInerney <Ian.S.McInerney at ieee.org>
5 * Copyright (C) 2020-2022 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#include <glib.h>
22#include <gio/gio.h>
23#include <gdk/gdk.h>
25#include <wx/filename.h>
26#include <wx/utils.h>
27
28
30{
31 // Disable proxy menu in Unity window manager. Only usual menubar works with
32 // wxWidgets (at least <= 3.1). When the proxy menu menubar is enable, some
33 // important things for us do not work: menuitems UI events and shortcuts.
34 wxString wm;
35
36 if( wxGetEnv( wxT( "XDG_CURRENT_DESKTOP" ), &wm ) && wm.CmpNoCase( wxT( "Unity" ) ) == 0 )
37 wxSetEnv( wxT( "UBUNTU_MENUPROXY" ), wxT( "0" ) );
38
39#if !wxUSE_GLCANVAS_EGL
40 // Force the use of X11 backend (or wayland-x11 compatibility layer). This is
41 // required until wxWidgets supports the Wayland compositors
42 wxSetEnv( wxT( "GDK_BACKEND" ), wxT( "x11" ) );
43#endif
44
45 // Set GTK2-style input instead of xinput2. This disables touchscreen and smooth
46 // scrolling. It's needed to ensure that we are not getting multiple mouse scroll
47 // events.
48 wxSetEnv( wxT( "GDK_CORE_DEVICE_EVENTS" ), wxT( "1" ) );
49}
50
51
52bool KIPLATFORM::ENV::MoveToTrash( const wxString& aPath, wxString& aError )
53{
54 GError* err = nullptr;
55 GFile* file = g_file_new_for_path( aPath.fn_str() );
56
57 bool retVal = g_file_trash( file, nullptr, &err );
58
59 // Extract the error string if the operation failed
60 if( !retVal && err )
61 aError = err->message;
62
63 g_clear_error( &err );
64 g_object_unref( file );
65
66 return retVal;
67}
68
69
70bool KIPLATFORM::ENV::IsNetworkPath( const wxString& aPath )
71{
72 // placeholder, we "nerf" behavior if its a network path so return false by default
73 return false;
74}
75
76
78{
79 wxString docsPath = g_get_user_data_dir();
80
81 if( docsPath.IsEmpty() )
82 {
83 wxFileName fallback;
84
85 fallback.AssignDir( g_get_home_dir() );
86 fallback.AppendDir( wxT( ".local" ) );
87 fallback.AppendDir( wxT( "share" ) );
88 fallback.MakeAbsolute();
89
90 docsPath = fallback.GetFullPath();
91 }
92
93 return docsPath;
94}
95
96
98{
99 return g_get_user_config_dir();
100}
101
102
104{
105 return g_get_user_data_dir();
106}
107
108
110{
111 return g_get_user_data_dir();
112}
113
114
116{
117 return g_get_user_cache_dir();
118}
119
120
121bool KIPLATFORM::ENV::GetSystemProxyConfig( const wxString& aURL, PROXY_CONFIG& aCfg )
122{
123 return false;
124}
125
126
127bool KIPLATFORM::ENV::VerifyFileSignature( const wxString& aPath )
128{
129 return true;
130}
bool IsNetworkPath(const wxString &aPath)
Determines if a given path is a network shared file apth On Windows for example, any form of path is ...
void Init()
Perform environment initialization tasks.
bool GetSystemProxyConfig(const wxString &aURL, PROXY_CONFIG &aCfg)
Retrieves platform level proxying requirements to reach the given url.
wxString GetUserDataPath()
Retrieves the operating system specific path for a user's data store.
wxString GetDocumentsPath()
Retrieves the operating system specific path for a user's documents.
bool MoveToTrash(const wxString &aPath, wxString &aError)
Move the specified file/directory to the trash bin/recycle bin.
wxString GetUserLocalDataPath()
Retrieves the operating system specific path for a user's local data store.
wxString GetUserConfigPath()
Retrieves the operating system specific path for a user's configuration store.
wxString GetUserCachePath()
Retrieves the operating system specific path for user's application cache.
bool VerifyFileSignature(const wxString &aPath)
Validates the code signing signature of a given file This is most likely only ever going to be applic...