Skip to content

Linux + iPhone Continuity / iMessage / SMS

stup out gtk app

Zack Bartelbae4bad1c1ed
diff --git a/src/cli/main.cpp b/src/cli/main.cpp
index 883d3b1..1359985 100644
--- a/src/cli/main.cpp
+++ b/src/cli/main.cpp
@@ -1,18 +1,6 @@
-#include <cstring>
-#include <filesystem>
-#include <fstream>
#include <iostream>
-#include <nlohmann/json.hpp>
#include <string>
-#include <sys/socket.h>
-#include <sys/un.h>
-#include <sys/wait.h>
-#include <arpa/inet.h>
-#include <tether/base64.hpp>
-#include <tether/net.hpp>
-#include <tether/crypto.hpp>
-#include <unistd.h>
-#include <vector>
+#include <tether/client.hpp>
void print_help() {
std::cout << "tether - Wayland companion CLI\n\n"
@@ -33,89 +21,13 @@ void print_help() {
<< " tether --accept 9a4f21...\n";
}
-int connect_to_daemon(bool retry = true) {
- int sock = socket(AF_UNIX, SOCK_STREAM, 0);
- if (sock < 0)
- return -1;
-
- sockaddr_un addr{};
- addr.sun_family = AF_UNIX;
- std::string path = tether::get_runtime_dir() + "/tetherd.sock";
- std::strncpy(addr.sun_path, path.c_str(), sizeof(addr.sun_path) - 1);
-
- if (connect(sock, (sockaddr*)&addr, sizeof(addr)) < 0) {
- close(sock);
- if (!retry)
- return -1;
-
- // Let's spawn the daemon in the background
- pid_t pid = fork();
- if (pid == 0) {
- // Child process
- std::filesystem::path self_path = std::filesystem::read_symlink("/proc/self/exe");
- std::string daemon_path = (self_path.parent_path() / "tetherd").string();
-
- // Double fork trick to detach completely without zombies
- if (fork() == 0) {
- // Grandchild - disconnects standard output to not spam CLI calling terminal
- freopen("/dev/null", "w", stdout);
- freopen("/dev/null", "w", stderr);
- freopen("/dev/null", "r", stdin);
-
- execl(daemon_path.c_str(), "tetherd", nullptr);
- // Fallback to path lookup if it wasn't strictly adjacent
- execlp("tetherd", "tetherd", nullptr);
- exit(1); // Abort if launch failed
- }
- exit(0); // Intermediate child exits immediately
- } else if (pid > 0) {
- // Parent waits for intermediate child
- int status;
- waitpid(pid, &status, 0);
-
- // Give daemon a generous 300ms to spin up epoll and wayland
- usleep(300000);
- return connect_to_daemon(false);
- }
- return -1;
- }
- return sock;
-}
-
-SSL* g_ssl = nullptr;
-int g_sock = -1;
-
-std::string send_and_wait(const std::string& cmd) {
- char buf[65536];
-
- if (g_ssl) {
- int w = SSL_write(g_ssl, cmd.c_str(), cmd.size());
- if (w <= 0) return "";
- int n = SSL_read(g_ssl, buf, sizeof(buf) - 1);
- if (n > 0) {
- buf[n] = '\0';
- return std::string(buf);
- }
- } else {
- write(g_sock, cmd.c_str(), cmd.size());
- ssize_t n = read(g_sock, buf, sizeof(buf) - 1);
- if (n > 0) {
- buf[n] = '\0';
- return std::string(buf);
- }
- }
- return "";
-}
-
int main(int argc, char* argv[]) {
if (argc < 2) {
print_help();
return 0;
}
- std::string action;
- std::string arg_val;
- std::string host = "";
+ std::string action, arg_val, host = "";
int port = 5134;
for (int i = 1; i < argc; ++i) {
@@ -123,29 +35,18 @@ int main(int argc, char* argv[]) {
if (arg == "-h" || arg == "--help") {
print_help();
return 0;
- } else if (arg == "-g" || arg == "--get-clipboard") {
- action = "get";
- } else if (arg == "--list-devices") {
- action = "list";
- } else if (arg == "--accept") {
- action = "accept";
- if (i + 1 < argc && argv[i + 1][0] != '-') arg_val = argv[++i];
- } else if (arg == "--pair") {
- action = "pair";
- } else if (arg == "--host") {
- if (i + 1 < argc && argv[i + 1][0] != '-') host = argv[++i];
- } else if (arg == "--port") {
- if (i + 1 < argc && argv[i + 1][0] != '-') port = std::stoi(argv[++i]);
- } else if (arg == "-f" || arg == "--send-file") {
+ } else if (arg == "-g" || arg == "--get-clipboard") { action = "get"; }
+ else if (arg == "--list-devices") { action = "list"; }
+ else if (arg == "--pair") { action = "pair"; }
+ else if (arg == "--accept") { action = "accept"; if (i + 1 < argc && argv[i + 1][0] != '-') arg_val = argv[++i]; }
+ else if (arg == "--host") { if (i + 1 < argc && argv[i + 1][0] != '-') host = argv[++i]; }
+ else if (arg == "--port") { if (i + 1 < argc && argv[i + 1][0] != '-') port = std::stoi(argv[++i]); }
+ else if (arg == "-f" || arg == "--send-file") {
action = "file";
- if (i + 1 < argc && argv[i + 1][0] != '-') {
- arg_val = argv[++i];
- }
+ if (i + 1 < argc && argv[i + 1][0] != '-') arg_val = argv[++i];
} else if (arg == "-s" || arg == "--set-clipboard") {
action = "set";
- if (i + 1 < argc && argv[i + 1][0] != '-') {
- arg_val = argv[++i];
- }
+ if (i + 1 < argc && argv[i + 1][0] != '-') arg_val = argv[++i];
}
}
@@ -154,157 +55,53 @@ int main(int argc, char* argv[]) {
return 1;
}
+ tether::Client client;
+
+ // Fast-path local operations that don't need active daemon connection fundamentally
if (action == "list") {
- tether::Crypto::instance().init();
- std::cout << tether::Crypto::instance().get_known_hosts_dump() << "\n";
+ std::cout << client.list_devices() << "\n";
return 0;
} else if (action == "accept") {
- tether::Crypto::instance().init();
- tether::Crypto::instance().add_known_host("Paired Device", arg_val);
+ client.accept_device(arg_val);
std::cout << "Successfully paired device: " << arg_val << "\n";
return 0;
}
if (action == "set" && arg_val.empty()) {
- // Read from stdin ...
std::string line;
- while (std::getline(std::cin, line)) {
- arg_val += line + "\n";
- }
- if (!arg_val.empty() && arg_val.back() == '\n') {
- arg_val.pop_back();
- }
+ while (std::getline(std::cin, line)) arg_val += line + "\n";
+ if (!arg_val.empty() && arg_val.back() == '\n') arg_val.pop_back();
}
- if (!host.empty()) {
- // TCP TLS Connection
- g_sock = socket(AF_INET, SOCK_STREAM, 0);
- sockaddr_in addr{};
- addr.sin_family = AF_INET;
- addr.sin_port = htons(port);
- inet_pton(AF_INET, host.c_str(), &addr.sin_addr);
-
- if (connect(g_sock, (sockaddr*)&addr, sizeof(addr)) < 0) {
- std::cerr << "Failed to connect strictly over TCP.\n";
- return 1;
- }
-
- tether::Crypto::instance().init();
- SSL* ssl = SSL_new(tether::Crypto::instance().get_client_context());
- SSL_set_fd(ssl, g_sock);
- if (SSL_connect(ssl) <= 0) {
- std::cerr << "Network paired strictly rejected: SSL Handshake Failed.\n";
- return 1;
- }
- g_ssl = ssl;
- } else {
- // Unix Socket Fallback
- g_sock = connect_to_daemon();
- if (g_sock < 0) {
- std::cerr << "Failed to connect to daemon and automatic launch failed.\n";
- return 1;
- }
+ // Bind network abstraction natively
+ if (!client.connect(host, port)) {
+ std::cerr << "Explicit framework connection locally rejected! Did you target explicitly invalid TLS or is daemon broken?\n";
+ return 1;
}
+ std::string err;
if (action == "pair") {
- nlohmann::json j;
- j["command"] = "pair_request";
- j["device_name"] = "CLI Test Tools";
- std::string payload = j.dump() + "\n";
- std::string response = send_and_wait(payload);
- std::cout << "Pairing response: " << response << std::flush;
- if (g_ssl) SSL_free(g_ssl);
- close(g_sock);
- return 0;
- }
-
- if (action == "get") {
- nlohmann::json j;
- j["command"] = "clipboard_get";
- std::string payload = j.dump() + "\n";
-
- std::string response = send_and_wait(payload);
- try {
- nlohmann::json r = nlohmann::json::parse(response);
- if (r.contains("content")) {
- std::cout << r["content"].get<std::string>() << std::flush;
- } else if (r.contains("message") && r["message"] == "unauthorized") {
- std::cerr << "Unauthorized. You must pair this device first using a pair_request.\n";
- }
- } catch (...) {}
- } else if (action == "set") {
- nlohmann::json j;
- j["command"] = "clipboard_set";
- j["content"] = arg_val;
- std::string payload = j.dump() + "\n";
- std::string s_resp = send_and_wait(payload);
- if (s_resp.find("unauthorized") != std::string::npos) {
- std::cerr << "Unauthorized. Device not paired.\n";
- return 1;
- }
- } else if (action == "file") {
- if (arg_val.empty() || !std::filesystem::exists(arg_val)) {
- std::cerr << "Invalid or missing file path: " << arg_val << "\n";
+ std::cout << "Pairing response: " << client.pair(err) << std::flush;
+ } else if (action == "get") {
+ std::string clip = client.get_clipboard(err);
+ if (!err.empty()) {
+ std::cerr << err << "\n";
return 1;
}
-
- std::ifstream file(arg_val, std::ios::binary);
- if (!file.is_open()) {
- std::cerr << "Failed to open file.\n";
+ std::cout << clip << std::flush;
+ } else if (action == "set") {
+ if (!client.set_clipboard(arg_val, err)) {
+ std::cerr << err << "\n";
return 1;
}
-
- size_t file_size = std::filesystem::file_size(arg_val);
- std::string filename = std::filesystem::path(arg_val).filename().string();
- std::string transfer_id = "cli_" + std::to_string(time(nullptr));
-
- std::cout << "Uploading " << filename << " (" << file_size << " bytes)..." << std::endl;
-
- nlohmann::json j_start;
- j_start["command"] = "file_start";
- j_start["filename"] = filename;
- j_start["size"] = file_size;
- j_start["transfer_id"] = transfer_id;
- std::string s_resp = send_and_wait(j_start.dump() + "\n");
- if (s_resp.find("unauthorized") != std::string::npos) {
- std::cerr << "Unauthorized. Device not paired.\n";
- return 1;
- }
-
- const size_t chunk_size = 512 * 1024;
- std::vector<unsigned char> buffer(chunk_size);
- int chunk_idx = 0;
-
- while (file) {
- file.read(reinterpret_cast<char*>(buffer.data()), chunk_size);
- size_t bytes_read = file.gcount();
- if (bytes_read == 0)
- break;
-
- nlohmann::json j_chunk;
- j_chunk["command"] = "file_chunk";
- j_chunk["chunk_index"] = chunk_idx++;
- j_chunk["transfer_id"] = transfer_id;
- j_chunk["data"] = tether::base64_encode(buffer.data(), bytes_read);
-
- send_and_wait(j_chunk.dump() + "\n");
- }
-
- nlohmann::json j_end;
- j_end["command"] = "file_end";
- j_end["transfer_id"] = transfer_id;
-
- std::string resp = send_and_wait(j_end.dump() + "\n");
- try {
- nlohmann::json r = nlohmann::json::parse(resp);
- if (r.contains("status") && r["status"] == "success") {
- std::cout << "File transfer successfully saved.\n";
- }
- } catch (...) {
+ } else if (action == "file") {
+ std::cout << "Uploading " << arg_val << "..." << std::endl;
+ if (!client.send_file(arg_val, err)) {
+ std::cerr << "Transfer Failed: " << err << "\n";
+ return 1;
}
+ std::cout << "File transfer successfully saved.\n";
}
- if (g_ssl) SSL_free(g_ssl);
- close(g_sock);
return 0;
}
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt
index eee5fa0..aba1750 100644
--- a/src/core/CMakeLists.txt
+++ b/src/core/CMakeLists.txt
@@ -6,6 +6,7 @@ add_library(tether STATIC
src/base64.cpp
src/file_transfer.cpp
src/crypto.cpp
+ src/client.cpp
src/wayland.cpp
src/wayland_protocols/wayland.cpp
src/wayland_protocols/wlr-data-control-unstable-v1.cpp
diff --git a/src/core/include/tether/client.hpp b/src/core/include/tether/client.hpp
new file mode 100644
index 0000000..1f906f6
--- /dev/null
+++ b/src/core/include/tether/client.hpp
@@ -0,0 +1,37 @@
+#pragma once
+#include <string>
+#include <openssl/ssl.h>
+#include <vector>
+
+namespace tether {
+
+class Client {
+public:
+ Client();
+ ~Client();
+
+ // host="" limits targeting to UNIX Socket securely, implicitly triggering daemon boot!
+ bool connect(const std::string& host = "", int port = 5134);
+ void disconnect();
+
+ // Base Level payload loop
+ std::string send_and_wait(const std::string& payload);
+
+ // High Level Features
+ std::string get_clipboard(std::string& err_out);
+ bool set_clipboard(const std::string& text, std::string& err_out);
+
+ std::string list_devices();
+ bool accept_device(const std::string& fingerprint);
+ std::string pair(std::string& err_out);
+
+ bool send_file(const std::string& path, std::string& err_out);
+
+private:
+ int connect_unix(bool retry);
+
+ int sock_ = -1;
+ SSL* ssl_ = nullptr;
+};
+
+} // namespace tether
diff --git a/src/core/src/client.cpp b/src/core/src/client.cpp
new file mode 100644
index 0000000..64ab681
--- /dev/null
+++ b/src/core/src/client.cpp
@@ -0,0 +1,235 @@
+#include "tether/client.hpp"
+#include "tether/core.hpp"
+#include "tether/crypto.hpp"
+#include "tether/net.hpp"
+#include "tether/base64.hpp"
+
+#include <arpa/inet.h>
+#include <cstring>
+#include <filesystem>
+#include <fstream>
+#include <iostream>
+#include <nlohmann/json.hpp>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <sys/wait.h>
+#include <unistd.h>
+
+namespace tether {
+
+Client::Client() {}
+
+Client::~Client() {
+ disconnect();
+}
+
+void Client::disconnect() {
+ if (ssl_) {
+ SSL_free(ssl_);
+ ssl_ = nullptr;
+ }
+ if (sock_ >= 0) {
+ close(sock_);
+ sock_ = -1;
+ }
+}
+
+int Client::connect_unix(bool retry) {
+ int sock = socket(AF_UNIX, SOCK_STREAM, 0);
+ if (sock < 0) return -1;
+
+ sockaddr_un addr{};
+ addr.sun_family = AF_UNIX;
+ std::string path = tether::get_runtime_dir() + "/tetherd.sock";
+ std::strncpy(addr.sun_path, path.c_str(), sizeof(addr.sun_path) - 1);
+
+ if (::connect(sock, (sockaddr*)&addr, sizeof(addr)) < 0) {
+ close(sock);
+ if (!retry) return -1;
+
+ pid_t pid = fork();
+ if (pid == 0) {
+ std::filesystem::path self_path = std::filesystem::read_symlink("/proc/self/exe");
+ std::string daemon_path = (self_path.parent_path() / "tetherd").string();
+
+ if (fork() == 0) {
+ freopen("/dev/null", "w", stdout);
+ freopen("/dev/null", "w", stderr);
+ freopen("/dev/null", "r", stdin);
+
+ execl(daemon_path.c_str(), "tetherd", nullptr);
+ execlp("tetherd", "tetherd", nullptr);
+ exit(1);
+ }
+ exit(0);
+ } else if (pid > 0) {
+ int status;
+ waitpid(pid, &status, 0);
+ usleep(300000);
+ return connect_unix(false);
+ }
+ return -1;
+ }
+ return sock;
+}
+
+bool Client::connect(const std::string& host, int port) {
+ disconnect();
+
+ if (!host.empty()) {
+ sock_ = socket(AF_INET, SOCK_STREAM, 0);
+ sockaddr_in addr{};
+ addr.sin_family = AF_INET;
+ addr.sin_port = htons(port);
+ inet_pton(AF_INET, host.c_str(), &addr.sin_addr);
+
+ if (::connect(sock_, (sockaddr*)&addr, sizeof(addr)) < 0) {
+ return false;
+ }
+
+ tether::Crypto::instance().init();
+ ssl_ = SSL_new(tether::Crypto::instance().get_client_context());
+ SSL_set_fd(ssl_, sock_);
+ if (SSL_connect(ssl_) <= 0) {
+ return false;
+ }
+ return true;
+ } else {
+ sock_ = connect_unix(true);
+ return sock_ >= 0;
+ }
+}
+
+std::string Client::send_and_wait(const std::string& payload) {
+ char buf[1024 * 1024]; // Generous payload buffer
+
+ if (ssl_) {
+ int w = SSL_write(ssl_, payload.c_str(), payload.size());
+ if (w <= 0) return "";
+ int n = SSL_read(ssl_, buf, sizeof(buf) - 1);
+ if (n > 0) {
+ buf[n] = '\0';
+ return std::string(buf);
+ }
+ } else {
+ write(sock_, payload.c_str(), payload.size());
+ ssize_t n = read(sock_, buf, sizeof(buf) - 1);
+ if (n > 0) {
+ buf[n] = '\0';
+ return std::string(buf);
+ }
+ }
+ return "";
+}
+
+std::string Client::get_clipboard(std::string& err_out) {
+ nlohmann::json j;
+ j["command"] = "clipboard_get";
+ std::string response = send_and_wait(j.dump() + "\n");
+
+ try {
+ nlohmann::json r = nlohmann::json::parse(response);
+ if (r.contains("content")) {
+ return r["content"].get<std::string>();
+ } else if (r.contains("message") && r["message"] == "unauthorized") {
+ err_out = "Unauthorized. You must pair this device first.";
+ }
+ } catch (...) {}
+ return "";
+}
+
+bool Client::set_clipboard(const std::string& text, std::string& err_out) {
+ nlohmann::json j;
+ j["command"] = "clipboard_set";
+ j["content"] = text;
+ std::string s_resp = send_and_wait(j.dump() + "\n");
+ if (s_resp.find("unauthorized") != std::string::npos) {
+ err_out = "Unauthorized. Device not paired.";
+ return false;
+ }
+ return true;
+}
+
+std::string Client::list_devices() {
+ tether::Crypto::instance().init();
+ return tether::Crypto::instance().get_known_hosts_dump();
+}
+
+bool Client::accept_device(const std::string& fingerprint) {
+ tether::Crypto::instance().init();
+ tether::Crypto::instance().add_known_host("Paired App Instance", fingerprint);
+ return true;
+}
+
+std::string Client::pair(std::string& err_out) {
+ nlohmann::json j;
+ j["command"] = "pair_request";
+ j["device_name"] = "Tether Desktop Environment";
+ std::string response = send_and_wait(j.dump() + "\n");
+ return response;
+}
+
+bool Client::send_file(const std::string& path, std::string& err_out) {
+ if (path.empty() || !std::filesystem::exists(path)) {
+ err_out = "Invalid or missing file path.";
+ return false;
+ }
+
+ std::ifstream file(path, std::ios::binary);
+ if (!file.is_open()) {
+ err_out = "Failed to open file.";
+ return false;
+ }
+
+ size_t file_size = std::filesystem::file_size(path);
+ std::string filename = std::filesystem::path(path).filename().string();
+ std::string transfer_id = "cli_" + std::to_string(time(nullptr));
+
+ nlohmann::json j_start;
+ j_start["command"] = "file_start";
+ j_start["filename"] = filename;
+ j_start["size"] = file_size;
+ j_start["transfer_id"] = transfer_id;
+
+ std::string s_resp = send_and_wait(j_start.dump() + "\n");
+ if (s_resp.find("unauthorized") != std::string::npos) {
+ err_out = "Unauthorized. Device not paired.";
+ return false;
+ }
+
+ const size_t chunk_size = 512 * 1024;
+ std::vector<unsigned char> buffer(chunk_size);
+ int chunk_idx = 0;
+
+ while (file) {
+ file.read(reinterpret_cast<char*>(buffer.data()), chunk_size);
+ size_t bytes_read = file.gcount();
+ if (bytes_read == 0) break;
+
+ nlohmann::json j_chunk;
+ j_chunk["command"] = "file_chunk";
+ j_chunk["chunk_index"] = chunk_idx++;
+ j_chunk["transfer_id"] = transfer_id;
+ j_chunk["data"] = tether::base64_encode(buffer.data(), bytes_read);
+
+ send_and_wait(j_chunk.dump() + "\n");
+ }
+
+ nlohmann::json j_end;
+ j_end["command"] = "file_end";
+ j_end["transfer_id"] = transfer_id;
+
+ std::string resp = send_and_wait(j_end.dump() + "\n");
+ try {
+ nlohmann::json r = nlohmann::json::parse(resp);
+ if (r.contains("status") && r["status"] == "success") {
+ return true;
+ }
+ } catch (...) {
+ }
+
+ err_out = "Transfer sequence explicitly rejected externally.";
+ return false;
+}
+
+} // namespace tether
diff --git a/src/gtk/CMakeLists.txt b/src/gtk/CMakeLists.txt
index 7fd4a3a..e4dbd79 100644
--- a/src/gtk/CMakeLists.txt
+++ b/src/gtk/CMakeLists.txt
@@ -1,8 +1,13 @@
+find_package(PkgConfig REQUIRED)
+pkg_check_modules(GTK3 REQUIRED gtk+-3.0)
+
add_executable(tether-gtk
main.cpp
)
-target_link_libraries(tether-gtk PRIVATE tether)
+target_include_directories(tether-gtk PRIVATE ${GTK3_INCLUDE_DIRS})
+target_link_libraries(tether-gtk PRIVATE tether ${GTK3_LIBRARIES})
+target_compile_options(tether-gtk PRIVATE ${GTK3_CFLAGS_OTHER})
# Output into root build dir instead of nested build/src/gtk
set_target_properties(tether-gtk PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}")
diff --git a/src/gtk/main.cpp b/src/gtk/main.cpp
index a01e258..6c15376 100644
--- a/src/gtk/main.cpp
+++ b/src/gtk/main.cpp
@@ -1,8 +1,147 @@
+#include <gtk/gtk.h>
+#include <tether/client.hpp>
#include <iostream>
-#include <tether/core.hpp>
+#include <string>
+
+// Global persistent instance to maintain Wayland socket
+static tether::Client* g_client = nullptr;
+
+// UI Globals
+GtkWidget* text_view_clip;
+GtkWidget* lbl_status;
+GtkWidget* list_box_devices;
+
+void on_btn_get_clicked(GtkWidget* widget, gpointer data) {
+ if (!g_client) return;
+ std::string err;
+ std::string content = g_client->get_clipboard(err);
+ if (!err.empty()) {
+ gtk_label_set_text(GTK_LABEL(lbl_status), ("Error: " + err).c_str());
+ return;
+ }
+
+ GtkTextBuffer* buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text_view_clip));
+ gtk_text_buffer_set_text(buffer, content.c_str(), -1);
+ gtk_label_set_text(GTK_LABEL(lbl_status), "Clipboard successfully retrieved.");
+}
+
+void on_btn_set_clicked(GtkWidget* widget, gpointer data) {
+ if (!g_client) return;
+ GtkTextBuffer* buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text_view_clip));
+ GtkTextIter start, end;
+ gtk_text_buffer_get_bounds(buffer, &start, &end);
+ std::string text = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
+
+ std::string err;
+ if (g_client->set_clipboard(text, err)) {
+ gtk_label_set_text(GTK_LABEL(lbl_status), "Clipboard successfully updated.");
+ } else {
+ gtk_label_set_text(GTK_LABEL(lbl_status), ("Error: " + err).c_str());
+ }
+}
+
+void apply_css(GtkWidget* widget) {
+ GtkCssProvider* provider = gtk_css_provider_new();
+ const gchar* css =
+ "window { "
+ " background-color: @theme_bg_color; "
+ "} "
+ "textview { "
+ " background-color: @theme_base_color; "
+ " color: @theme_fg_color; "
+ " font-family: monospace; "
+ " border-radius: 8px; "
+ " padding: 12px; "
+ "} "
+ "button { "
+ " border-radius: 6px; "
+ " padding: 8px 16px; "
+ " font-weight: bold; "
+ "} "
+ "button:hover { "
+ " background-color: @theme_selected_bg_color; "
+ " color: @theme_selected_fg_color; "
+ "} "
+ ".header-label { "
+ " font-size: 16px; "
+ " font-weight: 800; "
+ " color: @theme_fg_color; "
+ "} "
+ ".status-label { "
+ " color: @theme_selected_bg_color; "
+ " font-weight: bold; "
+ "}";
+
+ gtk_css_provider_load_from_data(provider, css, -1, NULL);
+ gtk_style_context_add_provider_for_screen(gdk_screen_get_default(),
+ GTK_STYLE_PROVIDER(provider),
+ GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
+ g_object_unref(provider);
+}
+
+static void activate(GtkApplication* app, gpointer user_data) {
+ // Scaffold initial network multiplexer natively
+ if (!g_client) {
+ g_client = new tether::Client();
+ if (!g_client->connect()) {
+ std::cerr << "CRITICAL: Could not engage local unix tetherd pipeline natively.\n";
+ exit(1);
+ }
+ }
+
+ GtkWidget* window = gtk_application_window_new(app);
+ gtk_window_set_title(GTK_WINDOW(window), "Tether Control Center");
+ gtk_window_set_default_size(GTK_WINDOW(window), 500, 400);
+
+ // Prefer Dark Theme
+ g_object_set(gtk_settings_get_default(), "gtk-application-prefer-dark-theme", TRUE, NULL);
+ apply_css(window);
+
+ GtkWidget* main_box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 16);
+ gtk_container_set_border_width(GTK_CONTAINER(main_box), 20);
+ gtk_container_add(GTK_CONTAINER(window), main_box);
+
+ // Header Frame
+ GtkWidget* header = gtk_label_new("Wayland Clipboard Engine");
+ gtk_widget_set_halign(header, GTK_ALIGN_START);
+ GtkStyleContext* ctx = gtk_widget_get_style_context(header);
+ gtk_style_context_add_class(ctx, "header-label");
+ gtk_box_pack_start(GTK_BOX(main_box), header, FALSE, FALSE, 0);
+
+ // Text View Frame
+ GtkWidget* scroll = gtk_scrolled_window_new(NULL, NULL);
+ gtk_widget_set_vexpand(scroll, TRUE);
+ text_view_clip = gtk_text_view_new();
+ gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text_view_clip), GTK_WRAP_WORD_CHAR);
+ gtk_container_add(GTK_CONTAINER(scroll), text_view_clip);
+ gtk_box_pack_start(GTK_BOX(main_box), scroll, TRUE, TRUE, 0);
+
+ // Button Row
+ GtkWidget* btn_box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 12);
+ GtkWidget* btn_get = gtk_button_new_with_label("Read From Host");
+ GtkWidget* btn_set = gtk_button_new_with_label("Push To Host");
+
+ g_signal_connect(btn_get, "clicked", G_CALLBACK(on_btn_get_clicked), NULL);
+ g_signal_connect(btn_set, "clicked", G_CALLBACK(on_btn_set_clicked), NULL);
+
+ gtk_box_pack_start(GTK_BOX(btn_box), btn_get, TRUE, TRUE, 0);
+ gtk_box_pack_start(GTK_BOX(btn_box), btn_set, TRUE, TRUE, 0);
+ gtk_box_pack_start(GTK_BOX(main_box), btn_box, FALSE, FALSE, 0);
+
+ // Status Footprint
+ lbl_status = gtk_label_new("Connected natively via UNIX sockets.");
+ gtk_widget_set_halign(lbl_status, GTK_ALIGN_CENTER);
+ gtk_style_context_add_class(gtk_widget_get_style_context(lbl_status), "status-label");
+ gtk_box_pack_start(GTK_BOX(main_box), lbl_status, FALSE, FALSE, 0);
+
+ gtk_widget_show_all(window);
+}
int main(int argc, char** argv) {
- std::cout << "tether-gtk version " << tether::get_version() << "\n";
- std::cout << "Starting GTK UI stub...\n";
- return 0;
+ GtkApplication* app = gtk_application_new("com.tether.desktop", G_APPLICATION_DEFAULT_FLAGS);
+ g_signal_connect(app, "activate", G_CALLBACK(activate), NULL);
+ int status = g_application_run(G_APPLICATION(app), argc, argv);
+ g_object_unref(app);
+ if (g_client) { delete g_client; }
+ return status;
}