implement --transparency/-x at the command line

Closes #100
This commit is contained in:
Justin Strickland 2013-06-16 21:27:10 -04:00 committed by Simon Gomizelj
parent 53ae4efc0b
commit 30ec184e77
2 changed files with 35 additions and 21 deletions

View File

@ -25,6 +25,8 @@ Set the termite window's title to \fITITLE\fP. This disables dynamic
titles. titles.
.IP "\fB\-c\fR, \fB\-\-config\fR\fB=\fR\fICONFIG\fR" .IP "\fB\-c\fR, \fB\-\-config\fR\fB=\fR\fICONFIG\fR"
Specify a path to an alternative config file to use. Specify a path to an alternative config file to use.
.IP "\fB\-x\fR, \fB\-\-transparency\fR\fB=\fR\fITRANSPARENCY\fR"
Sets the inital Transparency.
.IP "\fB\-\-geometry\fR\fB=\fR\fIGEOMETRY\fR" .IP "\fB\-\-geometry\fR\fB=\fR\fIGEOMETRY\fR"
Override the window geometry in pixels. Override the window geometry in pixels.
.IP "\fB\-\-display\fR\fB=\fR\fIDISPLAY\fR" .IP "\fB\-\-display\fR\fB=\fR\fIDISPLAY\fR"

View File

@ -88,7 +88,7 @@ struct hint_info {
struct config_info { struct config_info {
hint_info hints; hint_info hints;
char *browser; char *browser;
gboolean dynamic_title, urgent_on_bell, clickable_url; gboolean dynamic_title, urgent_on_bell, clickable_url, opacity_set;
int tag; int tag;
char *config_file; char *config_file;
}; };
@ -105,7 +105,7 @@ struct draw_cb_info {
}; };
static void launch_browser(char *browser, char *url); static void launch_browser(char *browser, char *url);
static void set_opacity(GtkWidget *window, VteTerminal *vte, double opacity);
static void window_title_cb(VteTerminal *vte, gboolean *dynamic_title); static void window_title_cb(VteTerminal *vte, gboolean *dynamic_title);
static gboolean key_press_cb(VteTerminal *vte, GdkEventKey *event, keybind_info *info); static gboolean key_press_cb(VteTerminal *vte, GdkEventKey *event, keybind_info *info);
static gboolean entry_key_press_cb(GtkEntry *entry, GdkEventKey *event, keybind_info *info); static gboolean entry_key_press_cb(GtkEntry *entry, GdkEventKey *event, keybind_info *info);
@ -130,6 +130,27 @@ void launch_browser(char *browser, char *url) {
g_spawn_async(nullptr, browser_cmd, nullptr, G_SPAWN_SEARCH_PATH, nullptr, nullptr, nullptr, nullptr); g_spawn_async(nullptr, browser_cmd, nullptr, G_SPAWN_SEARCH_PATH, nullptr, nullptr, nullptr, nullptr);
} }
static void set_opacity(GtkWidget *window, VteTerminal *vte, double opacity) {
vte_terminal_set_background_saturation(vte, opacity);
vte_terminal_set_background_transparent(vte, false);
GdkScreen *screen = gtk_widget_get_screen(GTK_WIDGET(window));
GdkVisual *visual;
if (opacity > 0.0 && (visual = gdk_screen_get_rgba_visual(screen))) {
vte_terminal_set_opacity(vte, (guint16)(0xffff * (1 - opacity)));
} else {
visual = gdk_screen_get_system_visual(screen);
vte_terminal_set_opacity(vte, G_MAXUINT16);
}
if (visual != gtk_widget_get_visual(GTK_WIDGET(window))) {
gtk_widget_set_visual(GTK_WIDGET(window), visual);
// TODO; need to make dynamic changes to the visual work
// the obvious way is simply to hide the window and the restore shown widgets
}
}
static void launch_in_directory(VteTerminal *vte) { static void launch_in_directory(VteTerminal *vte) {
const char *uri = vte_terminal_get_current_directory_uri(vte); const char *uri = vte_terminal_get_current_directory_uri(vte);
if (!uri) { if (!uri) {
@ -1212,24 +1233,8 @@ static void set_config(GtkWindow *window, VteTerminal *vte, config_info *info,
} }
if (auto opacity = get_config_double(config, "options", "transparency")) { if (auto opacity = get_config_double(config, "options", "transparency")) {
vte_terminal_set_background_saturation(vte, *opacity); if (!info->opacity_set) {
gboolean pseudo = cfg_bool("pseudo_transparency", FALSE); set_opacity(GTK_WIDGET(window), vte, *opacity);
vte_terminal_set_background_transparent(vte, pseudo);
GdkScreen *screen = gtk_widget_get_screen(GTK_WIDGET(window));
GdkVisual *visual;
if (*opacity > 0.0 && !pseudo && (visual = gdk_screen_get_rgba_visual(screen))) {
vte_terminal_set_opacity(vte, (guint16)(0xffff * (1 - *opacity)));
} else {
visual = gdk_screen_get_system_visual(screen);
vte_terminal_set_opacity(vte, G_MAXUINT16);
}
if (visual != gtk_widget_get_visual(GTK_WIDGET(window))) {
gtk_widget_set_visual(GTK_WIDGET(window), visual);
// TODO: need to make dynamic changes to the visual work
// the obvious way is simply to hide the window and then restore shown widgets
} }
} }
@ -1251,6 +1256,7 @@ int main(int argc, char **argv) {
GOptionContext *context = g_option_context_new(nullptr); GOptionContext *context = g_option_context_new(nullptr);
char *role = nullptr, *geometry = nullptr, *execute = nullptr, *config_file = nullptr; char *role = nullptr, *geometry = nullptr, *execute = nullptr, *config_file = nullptr;
char *title = nullptr; char *title = nullptr;
double trans = 0.0;
const GOptionEntry entries[] = { const GOptionEntry entries[] = {
{"role", 'r', 0, G_OPTION_ARG_STRING, &role, "The role to use", "ROLE"}, {"role", 'r', 0, G_OPTION_ARG_STRING, &role, "The role to use", "ROLE"},
{"geometry", 0, 0, G_OPTION_ARG_STRING, &geometry, "Window geometry", "GEOMETRY"}, {"geometry", 0, 0, G_OPTION_ARG_STRING, &geometry, "Window geometry", "GEOMETRY"},
@ -1260,6 +1266,7 @@ int main(int argc, char **argv) {
{"version", 'v', 0, G_OPTION_ARG_NONE, &version, "Version info", nullptr}, {"version", 'v', 0, G_OPTION_ARG_NONE, &version, "Version info", nullptr},
{"hold", 0, 0, G_OPTION_ARG_NONE, &hold, "Remain open after child process exits", nullptr}, {"hold", 0, 0, G_OPTION_ARG_NONE, &hold, "Remain open after child process exits", nullptr},
{"config", 'c', 0, G_OPTION_ARG_STRING, &config_file, "Path of config file", "CONFIG"}, {"config", 'c', 0, G_OPTION_ARG_STRING, &config_file, "Path of config file", "CONFIG"},
{"transparency", 'x', 0, G_OPTION_ARG_DOUBLE, &trans, "Initial transparency", "TRANSPARENCY"},
{} {}
}; };
g_option_context_add_main_entries(context, entries, nullptr); g_option_context_add_main_entries(context, entries, nullptr);
@ -1330,7 +1337,7 @@ int main(int argc, char **argv) {
nullptr}, nullptr},
{vi_mode::insert, 0, 0, 0, 0}, {vi_mode::insert, 0, 0, 0, 0},
{{nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, 0, 0, 0}, {{nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, 0, 0, 0},
nullptr, FALSE, FALSE, FALSE, -1, config_file} nullptr, FALSE, FALSE, FALSE, FALSE, -1, config_file}
}; };
load_config(GTK_WINDOW(window), vte, &info.config, geometry ? nullptr : &geometry); load_config(GTK_WINDOW(window), vte, &info.config, geometry ? nullptr : &geometry);
@ -1392,6 +1399,11 @@ int main(int argc, char **argv) {
g_free(geometry); g_free(geometry);
} }
if (trans) {
info.config.opacity_set = true;
set_opacity(GTK_WIDGET(window), vte, trans);
}
gtk_widget_grab_focus(vte_widget); gtk_widget_grab_focus(vte_widget);
gtk_widget_show_all(window); gtk_widget_show_all(window);
gtk_widget_hide(info.panel.panel); gtk_widget_hide(info.panel.panel);