dconf-editor 和 gsettings 不应该访问同一个数据库吗?

Rma*_*ano 40 gnome unity gsettings dconf system-settings

这基本上是一个“学术”问题——试图更好地理解配置系统的内部结构。

我知道dconf系统是gnome3中的新配置系统,它取代了(已弃用的)gconf;这一点从Gconf、Dconf、Gsettings 以及它们之间的关系就很清楚

在我看来,程序gsettingsdconf-editorwhere 只是两种不同的方式来访问同一个dconf数据库,这在什么是 dconf,它的功能是什么,我如何使用它中得到了证实

编辑:我发现有人注意到它在某些架构名称中的大小写有所不同,请参见此处 --- dconf 架构名称是否区分大小写?; 但似乎差异不仅限于此。在一个答案中有一个不匹配的例子,但我没有找到原因的解释

但是最近我发现从gsettings和访问的密钥dconf-editor不一样。例如,对于设置vinodconf-editororg.gnome.desktop.remote-access(见下面的截图),而在gsettings它们是下 org.gnome.Vino。有一些文档可以解释差异吗?

gsettings 中

(0)samsung-romano:~/tmp/try% gsettings list-recursively org.gnome.Vino
org.gnome.Vino alternative-port uint16 5900
org.gnome.Vino authentication-methods ['none']
org.gnome.Vino disable-background false
[...]
Run Code Online (Sandbox Code Playgroud)

和:

(0)samsung-romano:~/tmp/try% gsettings list-recursively org.gnome.desktop.remote-access
No such schema 'org.gnome.desktop.remote-access'
Run Code Online (Sandbox Code Playgroud)

但是在dconf-editor 中

dconf-编辑器

use*_*.dz 44

  • dconf-editor用于schema path显示设置数据树。用于在 GVariant 数据库中存储数据的相同结构。

  • gsettings(来自 glib-2.0)用于schema id显示/获取设置数据。与使用 GSetttings API 的任何其他应用程序相同的方式。

  • 由应用程序开发人员按照他/她的意愿进行设置。(对规范命名有一些限制)。Sopath可能不同于id但大多数应用程序开发人员更喜欢使用相同的单词系列/组合。有些不保留相同的大小写。来自 Gnome 的示例跟踪器项目

    <schema id="org.freedesktop.Tracker.Miner" path="/org/freedesktop/tracker/miner/" />
    
    Run Code Online (Sandbox Code Playgroud)

    除此之外,一些替代应用程序共享属于 Gnome 桌面的相同设置。例子:input-sources


  • 首先,应用程序不应该乱dconf

    来自dconf项目页面的介绍:

    dconf是一个低级配置系统。它的主要目的是在没有配置存储系统的平台上为 GSettings 提供后端。

  • 数据存储在哪里?(参考:https : //wiki.gnome.org/Projects/dconf/SystemAdministrators

    配置文件是配置数据库的列表。Gnome 和 Unity 似乎使用相同的配置文件。

    $ cat /etc/dconf/profile/gdm
    user-db:user
    system-db:gdm
    
    Run Code Online (Sandbox Code Playgroud)
    1. user-db:user:配置文件中的第一个数据库是可读写的rw,它是在用户的主目录中创建的。

      $ file ~/.config/dconf/user
      /home/sneetsher/.config/dconf/user: GVariant Database file, version 0
      
      Run Code Online (Sandbox Code Playgroud)
    2. system-db:gdm: 只读

      $ file /etc/dconf/db/gdm
      /etc/dconf/db/gdm: GVariant Database file, version 0
      
      Run Code Online (Sandbox Code Playgroud)

      dconf除了db.d/*文件夹中的GVariant 数据库之外,还可以绑定文本样式存储。示例(注意文件路径,所以它是 的一部分system-db:gdm):

       $ cat /etc/dconf/db/gdm.d/00-upstream-settings
      
       # This file is part of the GDM packaging and should not be changed.
       #
       # Instead create your own file next to it with a higher numbered prefix,
       # and run
       #
       #       dconf update
       #
      
       [org/gnome/desktop/a11y/keyboard]
       enable=true
      
       [org/gnome/desktop/background]
       show-desktop-icons=false
       ...
      
      Run Code Online (Sandbox Code Playgroud)
  • 模式文件:schema id&schema path ( *.gschema.xml)之间的关系

    我的 Quickly 应用程序的 data/glib-2.0 文件夹中的架构 XML 文件是什么?by trent展示了在 Quickly 应用程序中使用 GSettings API 的一个很好的例子,以及他根据经验得出的结论。

    回到维诺。每个使用 GSsettings 的应用程序都应该定义它的架构并且应该将它们存储/安装在/usr/share/glib-2.0/schemas/(它是一个 glib 目录)中:

    $ dpkg -L vino | grep -i glib-2.0
    /usr/share/glib-2.0
    /usr/share/glib-2.0/schemas
    /usr/share/glib-2.0/schemas/org.gnome.Vino.enums.xml
    /usr/share/glib-2.0/schemas/org.gnome.Vino.gschema.xml
    
    $ more /usr/share/glib-2.0/schemas/org.gnome.Vino.gschema.xml
    <schemalist>
      <schema id='org.gnome.Vino' path='/org/gnome/desktop/remote-access/'>
        <key name='enabled' type='b'>
          <summary>Enable remote access to the desktop</summary>
          <description>
            If true, allows remote access to the desktop via the RFB
            protocol. Users on remote machines may then connect to the
            desktop using a VNC viewer.
          </description>
          <default>false</default>
        </key>
    
        <key name='prompt-enabled' type='b'>
          <summary>Prompt the user before completing a connection</summary>
          <description>
            If true, remote users accessing the desktop are not allowed
            access until the user on the host machine approves the
            connection. Recommended especially when access is not password
            protected.
          </description>
          <default>true</default>
        </key>
    ...
    
    Run Code Online (Sandbox Code Playgroud)

    如果您注意到,架构是用id和定义的path。模式文件名跟在id值之后。

    <schema id='org.gnome.Vino' path='/org/gnome/desktop/remote-access/'>
    
    Run Code Online (Sandbox Code Playgroud)
  • *.enums.xml文件用于自定义枚举声明,在*.gschema.xml相同的schema id.

    $ cat /usr/share/glib-2.0/schemas/org.gnome.Vino.enums.xml
    <!-- Generated data (by glib-mkenums) -->
    
    <schemalist>
      <enum id='org.gnome.Vino.VinoIconVisibility'>
        <value nick='never' value='0'/>
        <value nick='always' value='1'/>
        <value nick='client' value='2'/>
      </enum>
    </schemalist>
    
    <!-- Generated data ends here -->
    
    $ gsettings range org.gnome.Vino icon-visibility
    enum
    'never'
    'always'
    'client'
    
    $ gsettings get org.gnome.Vino icon-visibility
    'client'
    
    Run Code Online (Sandbox Code Playgroud)
  • 编译架构(参考:玩 dconf 和 gnome-tweak-tool

    作为安装过程的一部分(它有一个 dpkg 触发器),使用glib-compile-schemas工具(来自 glib)编译模式

    sudo glib-compile-schemas /usr/share/glib-2.0/schemas
    
    Run Code Online (Sandbox Code Playgroud)

    *.gschema.xml 将被编译为二进制文件 /usr/share/glib-2.0/schemas/gschemas.compiled

  • 供应商覆盖文件( *.gschema.override)

    除了架构文件,glib-compile-schemas读取供应商覆盖文件,这些文件是可以覆盖架构中键的默认值的关键文件(参考:)man glib-compile-schemas。它们包含 Ubuntu 发行版所做的更改,以覆盖上游模式默认值。

    $ ls /usr/share/glib-2.0/schemas/*.gschema.override
    /usr/share/glib-2.0/schemas/10_compiz-gnome.gschema.override
    /usr/share/glib-2.0/schemas/10_desktop-base.gschema.override
    /usr/share/glib-2.0/schemas/10_evolution-common.gschema.override
    /usr/share/glib-2.0/schemas/10_gnome-settings-daemon.gschema.override
    /usr/share/glib-2.0/schemas/10_gnome-shell.gschema.override
    /usr/share/glib-2.0/schemas/10_gnome-system-log.gschema.override
    /usr/share/glib-2.0/schemas/10_gsettings-desktop-schemas.gschema.override
    /usr/share/glib-2.0/schemas/10_libgtk-3-common.gschema.override
    /usr/share/glib-2.0/schemas/10_ubuntu-settings.gschema.override
    /usr/share/glib-2.0/schemas/20_ubuntu-gnome-default-settings.gschema.override
    
    $ cat /usr/share/glib-2.0/schemas/10_gnome-settings-daemon.gschema.override
    [org.gnome.desktop.wm.keybindings]
    switch-input-source=['<Super>space']
    switch-input-source-backward=['<Shift><Super>space']
    
    Run Code Online (Sandbox Code Playgroud)

    覆盖文件使用示例,请参阅如何自定义 Ubuntu Live CD?(5.定制2:背景和主题)。

  • 锁定文件

    目前,dconf 仅支持按键锁定,不支持子路径锁定。用户定义的值仍将存储在其中,user-db但不会对应用程序产生影响。dconf/gsettings 为那些锁定的键返回默认值。锁定文件存储在db.d/locks/. 例子:

    $ cat /etc/dconf/db/gdm.d/locks/00-upstream-settings-locks 
    /org/gnome/desktop/a11y/keyboard/enable
    /org/gnome/desktop/background/show-desktop-icons
    /org/gnome/desktop/lockdown/disable-application-handlers
    /org/gnome/desktop/lockdown/disable-command-line
    /org/gnome/desktop/lockdown/disable-lock-screen
    /org/gnome/desktop/lockdown/disable-log-out
    /org/gnome/desktop/lockdown/disable-printing
    /org/gnome/desktop/lockdown/disable-print-setup
    /org/gnome/desktop/lockdown/disable-save-to-disk
    /org/gnome/desktop/lockdown/disable-user-switching
    ...
    
    Run Code Online (Sandbox Code Playgroud)

    修改锁后,要生效运行:

    sudo dconf update
    
    Run Code Online (Sandbox Code Playgroud)

    一个很好的展示:dconf 设置:默认值和锁

  • 更改全局设置

    gsettings/的默认值dconf-editor是编辑user-db. 要更改system-db,请编写新的覆盖文件并重新编译架构。

    我无法让它工作:

    sudo su gdm -c 'gsettings ...'
    
    Run Code Online (Sandbox Code Playgroud)

    这里的其他答案都不是Set Default/Global Gnome Preferences (Gnome 3),可能是旧版本。