diff --git a/.travis.yml b/.travis.yml index 696347657..3eeb16820 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,6 +6,11 @@ compiler: - gcc - clang +env: + - BUILD_TYPE=Release + - BUILD_TYPE=Debug + - BUILD_TYPE=ASAN + arch: packages: - cmake @@ -19,7 +24,7 @@ arch: - wlc-git - libcap script: - - "cmake ." + - "cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE ." - "make" script: diff --git a/CMake/FindJsonC.cmake b/CMake/FindJsonC.cmake index 2ca0df39f..bbf6930cf 100644 --- a/CMake/FindJsonC.cmake +++ b/CMake/FindJsonC.cmake @@ -8,10 +8,22 @@ # find_package(PkgConfig) -pkg_check_modules(PC_JSONC QUIET JSONC) + +if (JsonC_FIND_REQUIRED) + set(_pkgconfig_REQUIRED "REQUIRED") +else() + set(_pkgconfig_REQUIRED "") +endif() + +if(JsonC_FIND_VERSION) + pkg_check_modules(PC_JSONC ${_pkgconfig_REQUIRED} json-c=${JsonC_FIND_VERSION}) +else() + pkg_check_modules(PC_JSONC ${_pkgconfig_REQUIRED} json-c) +endif() + find_path(JSONC_INCLUDE_DIRS NAMES json-c/json.h HINTS ${PC_JSONC_INCLUDE_DIRS}) find_library(JSONC_LIBRARIES NAMES json-c HINTS ${PC_JSONC_LIBRARY_DIRS}) - include(FindPackageHandleStandardArgs) + find_package_handle_standard_args(JSONC DEFAULT_MSG JSONC_LIBRARIES JSONC_INCLUDE_DIRS) mark_as_advanced(JSONC_LIBRARIES JSONC_INCLUDE_DIRS) diff --git a/CMakeLists.txt b/CMakeLists.txt index 95f539e7d..dc5215708 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,16 +2,23 @@ cmake_minimum_required(VERSION 3.1.0) project(sway C) -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g") +add_compile_options(-g) set(CMAKE_C_STANDARD 99) set(CMAKE_C_EXTENSIONS OFF) set(CMAKE_POSITION_INDEPENDENT_CODE ON) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin) -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall") -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wextra") -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-parameter") -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-result") -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror") +add_compile_options(-Wall -Wextra -Wno-unused-parameter -Wno-unused-result -Werror) + +# Add Address Sanitiezed build type +set(CMAKE_C_FLAGS_ASAN + "${CMAKE_C_FLAGS_DEBUG} -fsanitize=address -fno-omit-frame-pointer" + CACHE STRING "Flags used by the C compiler during address sanitizer builds." + FORCE ) +mark_as_advanced( + CMAKE_C_FLAGS_ASAN + CMAKE_EXE_LINKER_FLAGS_DEBUG + CMAKE_SHARED_LINKER_FLAGS_DEBUG + ) list(INSERT CMAKE_MODULE_PATH 0 ${CMAKE_CURRENT_SOURCE_DIR}/CMake @@ -52,7 +59,7 @@ if (LD_LIBRARY_PATH) add_definitions(-D_LD_LIBRARY_PATH="${LD_LIBRARY_PATH}") endif() -find_package(JsonC REQUIRED) +find_package(JsonC 0.12.1 REQUIRED) find_package(PCRE REQUIRED) find_package(WLC REQUIRED) find_package(Wayland REQUIRED) @@ -61,7 +68,7 @@ find_package(Cairo REQUIRED) find_package(Pango REQUIRED) find_package(GdkPixbuf) find_package(PAM) -find_package(DBus) +find_package(DBus 1.10) find_package(LibInput REQUIRED) diff --git a/README.de.md b/README.de.md index 92a15b995..701cc34fc 100644 --- a/README.de.md +++ b/README.de.md @@ -60,7 +60,7 @@ Abhängigkeiten: * libcap * asciidoc * pcre -* json-c +* json-c <= 0.12.1 * pango * cairo * gdk-pixbuf2 * @@ -82,7 +82,7 @@ Führe diese Befehle aus: In Systemen mit logind musst du `sway` einige Capabilities geben: - sudo setcap "cap_sys_ptrace,cap_sys_tty_config=eip" /usr/bin/sway + sudo setcap "cap_sys_ptrace,cap_sys_tty_config=eip" /usr/local/bin/sway In Systemen ohne logind musst du `sway` das suid-Flag geben: diff --git a/README.el.md b/README.el.md index 1e5b83582..df39364fe 100644 --- a/README.el.md +++ b/README.el.md @@ -53,7 +53,7 @@ To username μου στο Freenode είναι kon14 και θα με βρείτ * libcap * asciidoc * pcre -* json-c +* json-c <= 0.12.1 * pango * cairo * gdk-pixbuf2 * @@ -75,7 +75,7 @@ _\*\*Απαιτείται μόνο για swaylock_ Σε συστήματα με logind, χρειάζεται να ορίσετε μερικά δικαιώματα caps στο εκτελέσιμο αρχείο: - sudo setcap "cap_sys_ptrace,cap_sys_tty_config=eip" /usr/bin/sway + sudo setcap "cap_sys_ptrace,cap_sys_tty_config=eip" /usr/local/bin/sway Σε συστήματα χωρίς logind, χρειάζεται να θέσετε το suid bit στο εκτελέσιμο αρχείο: diff --git a/README.fr.md b/README.fr.md index 03b5a803f..47b6c4101 100644 --- a/README.fr.md +++ b/README.fr.md @@ -55,7 +55,7 @@ Installez les dépendances : * libcap * asciidoc * pcre -* json-c +* json-c <= 0.12.1 * pango * cairo * gdk-pixbuf2 * @@ -77,7 +77,7 @@ Exécutez ces commandes : Sur les systèmes avec logind, vous devez définir quelques caps sur le binaire : - sudo setcap "cap_sys_ptrace,cap_sys_tty_config=eip" /usr/bin/sway + sudo setcap "cap_sys_ptrace,cap_sys_tty_config=eip" /usr/local/bin/sway Sur les systèmes sans logind, vous devez suid le binaire de sway : diff --git a/README.it.md b/README.it.md index ca3e1ea3b..f5e0d8e2d 100644 --- a/README.it.md +++ b/README.it.md @@ -56,7 +56,7 @@ Installa queste dipendenze: * libcap * asciidoc * pcre -* json-c +* json-c <= 0.12.1 * pango * cairo * gdk-pixbuf2 * @@ -78,7 +78,7 @@ Esegui questi comandi: Per i sistemi con logind, devi impostare un paio di caps sull'eseguibile: - sudo setcap "cap_sys_ptrace,cap_sys_tty_config=eip" /usr/bin/sway + sudo setcap "cap_sys_ptrace,cap_sys_tty_config=eip" /usr/local/bin/sway Per i sistemi senza logind, devi cambiare i permessi (suid): diff --git a/README.ja.md b/README.ja.md index 7573ecc4a..2e8f9bfbc 100644 --- a/README.ja.md +++ b/README.ja.md @@ -3,43 +3,40 @@ "**S**irCmpwn's **Way**land compositor"は**開発中**の i3互換な[Wayland](http://wayland.freedesktop.org/)コンポジタです。 [FAQ](https://github.com/swaywm/sway/wiki)も合わせてご覧ください。 -[IRC チャンネル](http://webchat.freenode.net/?channels=sway&uio=d4) (#sway on -irc.freenode.net)もあります。 +[IRC チャンネル](http://webchat.freenode.net/?channels=sway&uio=d4) (#sway on irc.freenode.net)もあります。 + +**注意**: Swayは現在*凍結中*であり、Swayとwlrootsの統合が完了するまで、新たな機能は追加されません。バグフィックスは行われます。詳しくは[この記事](https://drewdevault.com/2017/10/09/Future-of-sway.html)をご覧ください。wlrootsとの統合状況については、[このチケット](https://github.com/swaywm/sway/issues/1390)をご覧ください。 [![](https://sr.ht/ICd5.png)](https://sr.ht/ICd5.png) -もしSwayの開発を支援したい場合は[SirCmpwnのPatreon](https://patreon.com/sircmpwn)や -[こちら](https://github.com/swaywm/sway/issues/986)をご覧ください。 +Swayの開発を支援したい場合は、[SirCmpwnのPatreon](https://patreon.com/sircmpwn)や、特定の機能に対する[報奨金のページ](https://github.com/swaywm/sway/issues/986)から寄付ができます。誰でも報奨金を請求できますし、自分の欲しい機能に報奨金を懸ける事も出来ます。またSwayのメンテナンスを支援するには、Patreonがより有用です。 -誰でも賞金を受け取る事ができますし、自分の欲しい機能に賞金を掛ける事が出来ます。 -PatreonはSwayの開発を支援するのにもっとも便利です。 +## 日本語サポート +SirCmpwnは、日本語でのサポートをIRCとGitHubで行います。タイムゾーンはUTC-4です。 -## リリース +## リリースの署名 -Swayのリリースは[B22DA89A](http://pgp.mit.edu/pks/lookup?op=vindex&search=0x52CB6609B22DA89A)で書名されて -[GitHub](https://github.com/swaywm/sway/releases)で公開されています。 +Swayのリリースは[B22DA89A](http://pgp.mit.edu/pks/lookup?op=vindex&search=0x52CB6609B22DA89A)で署名され、[GitHub](https://github.com/swaywm/sway/releases)で公開されています。 ## 開発状況 -- [i3のサポート](https://github.com/swaywm/sway/issues/2) -- [IPCのサポート](https://github.com/swaywm/sway/issues/98) -- [i3barのサポート](https://github.com/swaywm/sway/issues/343) -- [i3-gapsのサポート](https://github.com/swaywm/sway/issues/307) -- [セキュリティ対応](https://github.com/swaywm/sway/issues/984) +- [i3の機能のサポート](https://github.com/swaywm/sway/issues/2) +- [IPCの機能のサポート](https://github.com/swaywm/sway/issues/98) +- [i3barの機能のサポート](https://github.com/swaywm/sway/issues/343) +- [i3-gapsの機能のサポート](https://github.com/swaywm/sway/issues/307) +- [セキュリティ機能](https://github.com/swaywm/sway/issues/984) ## インストール ### パッケージから -Swayは沢山のディストリビューションで提供されています。"sway"パッケージをインストールしてみてください。 -もし、パッケージが存在しないならば、[このページ](https://github.com/swaywm/sway/wiki/Unsupported-packages) -を参照してインストールしてみてください。 +Swayは沢山のディストリビューションで提供されています。"sway"パッケージのインストールを試してください。パッケージが存在しない場合は、[このページ](https://github.com/swaywm/sway/wiki/Unsupported-packages)で、あなたのディストリビューションでのインストールに関する情報を調べてください。 -もし、Swayのパッケージを提供したいならば、SwayのIRCチャンネルか"sir@cmpwn.com"に連絡してください。 +あなたのディストリビューションにSwayのパッケージを提供したい場合は、SwayのIRCチャンネルを訪れるか、sir@cmpwn.comにメールを送り、相談してください。 -### ソースコードから +### ソースコードからコンパイル -まずはコンパイルや実行に必要なソフトウェアやライブラリをインストールしてください。: +次の依存パッケージをインストールしてください: * cmake * [wlc](https://github.com/Cloudef/wlc) @@ -49,7 +46,7 @@ Swayは沢山のディストリビューションで提供されています。" * libcap * asciidoc * pcre -* json-c +* json-c <= 0.12.1 * pango * cairo * gdk-pixbuf2 * @@ -57,11 +54,11 @@ Swayは沢山のディストリビューションで提供されています。" * imagemagick (swaygrabでスクリーンショットを撮るのに必要です) * ffmpeg (swaygrabで画面を録画するのに必要です) -_\*swaybar,swaybg,swaylockが使用します_ +_\*swaybar,swaybg,swaylockでのみ必要です_ -_\*\*swaylockが使用します_ +_\*\*swaylockでのみ必要です_ -ターミナルで次のコマンドを実行してください: +次のコマンドを実行してください: mkdir build cd build @@ -69,22 +66,19 @@ _\*\*swaylockが使用します_ make sudo make install -logindを使用している場合はバイナリにcapを設定してください: +logindを使用しているシステムでは、バイナリにいくつかのケーパビリティを設定する必要があります: - sudo setcap "cap_sys_ptrace,cap_sys_tty_config=eip" /usr/bin/sway + sudo setcap "cap_sys_ptrace,cap_sys_tty_config=eip" /usr/local/bin/sway -logindを使用していない場合はバイナリにsuidを設定してください: +logindを使用していないシステムでは、バイナリにsuidを設定する必要があります: sudo chmod a+s /usr/local/bin/sway ## 設定 -もし、既にi3を使用しているなら、i3のコンフィグファイルを`~/.config/sway/config`にコピーすれば動きます。 -そうでないならば、サンプルのコンフィグファイルを`~/.config/sway/config`にコピーしてください。 -サンプルのコンフィグファイルは基本的には`/etc/sway/config`にあります。 -`man 5 sway`で各種設定について確認できます。 +既にi3を使用している場合は、i3の設定ファイルを`~/.config/sway/config`にコピーすれば動きます。そうでない場合は、サンプルの設定ファイルを`~/.config/sway/config`にコピーしてください。サンプルの設定ファイルは、通常`/etc/sway/config`にあります。`man 5 sway`を実行することで、設定に関する情報を見ることができます。 ## 実行 -`sway`をTTYから実行してください。いくつかのDesktopManagerはSwayからサポートされていませんが、動く場合もあります(gdmは特にSwayと相性が良いそうです)。 +`sway`をTTYから実行してください。いくつかのディスプレイマネージャは動くかもしれませんが、Swayからサポートされていません(gdmは非常に良く動作することが知られています)。 diff --git a/README.md b/README.md index 5d0b29057..91b1677a7 100644 --- a/README.md +++ b/README.md @@ -61,11 +61,12 @@ Install dependencies: * libcap * asciidoc * pcre -* json-c +* json-c <= 0.12.1 * pango * cairo * gdk-pixbuf2 * * pam ** +* dbus >= 1.10 *** * imagemagick (required for image capture with swaygrab) * ffmpeg (required for video capture with swaygrab) @@ -73,6 +74,8 @@ _\*Only required for swaybar, swaybg, and swaylock_ _\*\*Only required for swaylock_ +_\*\*\*Only required for tray support_ + Run these commands: mkdir build @@ -83,7 +86,7 @@ Run these commands: On systems with logind, you need to set a few caps on the binary: - sudo setcap "cap_sys_ptrace,cap_sys_tty_config=eip" /usr/bin/sway + sudo setcap "cap_sys_ptrace,cap_sys_tty_config=eip" /usr/local/bin/sway On systems without logind, you need to suid the sway binary: diff --git a/README.pt.md b/README.pt.md index 96827623b..b5ca132f2 100644 --- a/README.pt.md +++ b/README.pt.md @@ -62,7 +62,7 @@ Antes de iniciar a compilação, instale as dependências: * libcap * asciidoc * pcre -* json-c +* json-c <= 0.12.1 * pango * cairo * gdk-pixbuf2 * @@ -84,7 +84,7 @@ Para compilar, execute estes comandos: Em sistemas com logind, configure as seguintes capacidades para o arquivo binário: - sudo setcap "cap_sys_ptrace,cap_sys_tty_config=eip" /usr/bin/sway + sudo setcap "cap_sys_ptrace,cap_sys_tty_config=eip" /usr/local/bin/sway Em sistemas sem logind, ative a *flag* de *suid* do arquivo binário: diff --git a/README.ru.md b/README.ru.md index 891adf999..4035b0fc9 100644 --- a/README.ru.md +++ b/README.ru.md @@ -55,7 +55,7 @@ Sway доступен во многих дистрибутивах и наход * libcap * asciidoc * pcre -* json-c +* json-c <= 0.12.1 * pango * cairo * gdk-pixbuf2 * @@ -77,7 +77,7 @@ _\*\*Требуется только для swaylock_ Если у вас logind: - sudo setcap "cap_sys_ptrace,cap_sys_tty_config=eip" /usr/bin/sway + sudo setcap "cap_sys_ptrace,cap_sys_tty_config=eip" /usr/local/bin/sway Иначе: diff --git a/README.uk.md b/README.uk.md index 02b64804a..2e107afc5 100644 --- a/README.uk.md +++ b/README.uk.md @@ -62,7 +62,7 @@ Sway доступний у багатьох дистрибутивах Linux (а * libcap * asciidoc * pcre -* json-c +* json-c <= 0.12.1 * pango * cairo * gdk-pixbuf2 * @@ -85,7 +85,7 @@ _\*\*Лише для swaylock_ На системах **з** logind, варто встановити декілька можливостей (caps) на виконуваний файл sway: - sudo setcap "cap_sys_ptrace,cap_sys_tty_config=eip" /usr/bin/sway + sudo setcap "cap_sys_ptrace,cap_sys_tty_config=eip" /usr/local/bin/sway На системах **без** logind, необхідно встановити біт SUID на виконуваний файл sway: diff --git a/common/log.c b/common/log.c index af1bdc3f6..6dc9d7432 100644 --- a/common/log.c +++ b/common/log.c @@ -22,6 +22,12 @@ static const char *verbosity_colors[] = { [L_INFO ] = "\x1B[1;34m", [L_DEBUG ] = "\x1B[1;30m", }; +static const char verbosity_chars[] = { + [L_SILENT] = '\0', + [L_ERROR ] = 'E', + [L_INFO ] = 'I', + [L_DEBUG ] = 'D', +}; void init_log(log_importance_t verbosity) { if (verbosity != L_DEBUG) { @@ -62,6 +68,16 @@ void _sway_vlog(const char *filename, int line, log_importance_t verbosity, static struct tm *tm_info; char buffer[26]; + unsigned int c = verbosity; + if (c > sizeof(verbosity_colors) / sizeof(char *) - 1) { + c = sizeof(verbosity_colors) / sizeof(char *) - 1; + } + + // First, if not printing color, show the log level + if (!(colored && isatty(STDERR_FILENO)) && c != L_SILENT) { + fprintf(stderr, "%c: ", verbosity_chars[c]); + } + // get current time t = time(NULL); // convert time to local time (determined by the locale) @@ -70,11 +86,6 @@ void _sway_vlog(const char *filename, int line, log_importance_t verbosity, strftime(buffer, sizeof(buffer), "%x %X - ", tm_info); fprintf(stderr, "%s", buffer); - unsigned int c = verbosity; - if (c > sizeof(verbosity_colors) / sizeof(char *) - 1) { - c = sizeof(verbosity_colors) / sizeof(char *) - 1; - } - if (colored && isatty(STDERR_FILENO)) { fprintf(stderr, "%s", verbosity_colors[c]); } @@ -124,6 +135,8 @@ void sway_log_errno(log_importance_t verbosity, char* format, ...) { if (colored && isatty(STDERR_FILENO)) { fprintf(stderr, "%s", verbosity_colors[c]); + } else if (c != L_SILENT) { + fprintf(stderr, "%c: ", verbosity_chars[c]); } va_list args; diff --git a/include/swaybar/tray/tray.h b/include/swaybar/tray/tray.h index b718e555b..2d0662bed 100644 --- a/include/swaybar/tray/tray.h +++ b/include/swaybar/tray/tray.h @@ -27,6 +27,6 @@ void tray_upkeep(struct bar *bar); /** * Initializes the tray with D-Bus */ -void init_tray(); +void init_tray(struct bar *bar); #endif /* _SWAYBAR_TRAY_H */ diff --git a/sway/main.c b/sway/main.c index 6d13955c0..cc9147b8a 100644 --- a/sway/main.c +++ b/sway/main.c @@ -135,6 +135,29 @@ void detect_proprietary() { "You need nvidia, nvidia_modeset, nvidia_uvm, and nvidia_drm." "\x1B[0m\n"); } +#ifdef __linux__ + f = fopen("/sys/module/nvidia_drm/parameters/modeset", "r"); + if (f) { + char *line = read_line(f); + if (line && strstr(line, "Y")) { + // nvidia-drm.modeset is set to 0 + fprintf(stderr, "\x1B[1;31mWarning: You must load " + "nvidia-drm with the modeset option on to use " + "the proprietary driver. Consider adding " + "nvidia-drm.modeset=1 to your kernel command line " + "parameters.\x1B[0m\n"); + } + fclose(f); + free(line); + } else { + // nvidia-drm.modeset is not set + fprintf(stderr, "\x1B[1;31mWarning: You must load " + "nvidia-drm with the modeset option on to use " + "the proprietary driver. Consider adding " + "nvidia-drm.modeset=1 to your kernel command line " + "parameters.\x1B[0m\n"); + } +#else f = fopen("/proc/cmdline", "r"); if (f) { char *line = read_line(f); @@ -146,6 +169,7 @@ void detect_proprietary() { fclose(f); free(line); } +#endif } } diff --git a/swaybar/status_line.c b/swaybar/status_line.c index cc324fdb7..87e90caf4 100644 --- a/swaybar/status_line.c +++ b/swaybar/status_line.c @@ -440,7 +440,7 @@ bool status_line_mouse_event(struct bar *bar, int x, int y, uint32_t button) { json_object_object_add(event_json, "x", json_object_new_int(x)); json_object_object_add(event_json, "y", json_object_new_int(y)); - int len = snprintf(event_buff, sizeof(event_buff), "%s,\n", json_object_to_json_string(event_json)); + int len = snprintf(event_buff, sizeof(event_buff), "%s\n", json_object_to_json_string(event_json)); json_object_put(event_json); diff --git a/swaygrab/json.c b/swaygrab/json.c index 80dae299f..286085c35 100644 --- a/swaygrab/json.c +++ b/swaygrab/json.c @@ -4,6 +4,7 @@ #include #include #include +#include "log.h" #include "ipc-client.h" #include "swaygrab/json.h" @@ -12,7 +13,23 @@ static json_object *tree; void init_json_tree(int socketfd) { uint32_t len = 0; char *res = ipc_single_command(socketfd, IPC_GET_TREE, NULL, &len); - tree = json_tokener_parse(res); + struct json_tokener *tok = json_tokener_new_ex(256); + if (!tok) { + sway_abort("Unable to get json tokener."); + } + tree = json_tokener_parse_ex(tok, res, len); + if (!tree || tok->err != json_tokener_success) { + sway_abort("Unable to parse IPC response as JSON: %s", json_tokener_error_desc(tok->err)); + } + json_object *success; + json_object_object_get_ex(tree, "success", &success); + if (success && !json_object_get_boolean(success)) { + json_object *error; + json_object_object_get_ex(tree, "error", &error); + sway_abort("IPC request failed: %s", json_object_get_string(error)); + } + json_object_put(success); + json_tokener_free(tok); } void free_json_tree() { @@ -63,7 +80,9 @@ json_object *get_focused_container() { char *get_focused_output() { json_object *outputs, *output, *name; json_object_object_get_ex(tree, "nodes", &outputs); - + if (!outputs) { + sway_abort("Unabled to get focused output. No nodes in tree."); + } for (int i = 0; i < json_object_array_length(outputs); i++) { output = json_object_array_get_idx(outputs, i);