KiCad PCB EDA Suite
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-2021 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 <kiplatform/environment.h>
24 #include <wx/filename.h>
25 #include <wx/utils.h>
26 
27 
29 {
30  // Disable proxy menu in Unity window manager. Only usual menubar works with
31  // wxWidgets (at least <= 3.1). When the proxy menu menubar is enable, some
32  // important things for us do not work: menuitems UI events and shortcuts.
33  wxString wm;
34 
35  if( wxGetEnv( wxT( "XDG_CURRENT_DESKTOP" ), &wm ) && wm.CmpNoCase( wxT( "Unity" ) ) == 0 )
36  wxSetEnv ( wxT("UBUNTU_MENUPROXY" ), wxT( "0" ) );
37 
38  // Force the use of X11 backend (or wayland-x11 compatibility layer). This is
39  // required until wxWidgets supports the Wayland compositors
40  wxSetEnv( wxT( "GDK_BACKEND" ), wxT( "x11" ) );
41 
42  // Disable overlay scrollbars as they mess up wxWidgets window sizing and cause
43  // excessive redraw requests.
44  wxSetEnv( wxT( "GTK_OVERLAY_SCROLLING" ), wxT( "0" ) );
45 
46  // Set GTK2-style input instead of xinput2. This disables touchscreen and smooth
47  // scrolling. It's needed to ensure that we are not getting multiple mouse scroll
48  // events.
49  wxSetEnv( wxT( "GDK_CORE_DEVICE_EVENTS" ), wxT( "1" ) );
50 }
51 
52 
53 bool KIPLATFORM::ENV::MoveToTrash( const wxString& aPath, wxString& aError )
54 {
55  GError* err = nullptr;
56  GFile* file = g_file_new_for_path( aPath.fn_str() );
57 
58  bool retVal = g_file_trash( file, nullptr, &err );
59 
60  // Extract the error string if the operation failed
61  if( !retVal && err )
62  aError = err->message;
63 
64  g_clear_error( &err );
65  g_object_unref( file );
66 
67  return retVal;
68 }
69 
70 
71 bool KIPLATFORM::ENV::IsNetworkPath( const wxString& aPath )
72 {
73  // placeholder, we "nerf" behavior if its a network path so return false by default
74  return false;
75 }
76 
77 
79 {
80  wxString docsPath = g_get_user_data_dir();
81 
82  if( docsPath.IsEmpty() )
83  {
84  wxFileName fallback;
85 
86  fallback.AssignDir( g_get_home_dir() );
87  fallback.AppendDir( ".local" );
88  fallback.AppendDir( "share" );
89  fallback.MakeAbsolute();
90 
91  docsPath = fallback.GetFullPath();
92  }
93 
94  return docsPath;
95 }
96 
97 
99 {
100  return g_get_user_config_dir();
101 }
102 
103 
105 {
106  return g_get_user_cache_dir();
107 }
wxString GetDocumentsPath()
Retrieves the operating system specific path for a user's documents.
wxString GetUserCachePath()
Retrieves the operating system specific path for user's application cache.
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 ...
bool MoveToTrash(const wxString &aPath, wxString &aError)
Move the specified file/directory to the trash bin/recycle bin.
void Init()
Perform environment initialization tasks.
wxString GetUserConfigPath()
Retrieves the operating system specific path for a user's configuration store.