/*
* rofi
*
* MIT/X11 License
* Copyright © 2013-2022 Qball Cow <qball@gmpclient.org>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
/** The log domain of this dialog. */
#define G_LOG_DOMAIN "Modes.Window"
#include <config.h>
#ifdef WINDOW_MODE
#include <errno.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <unistd.h>
#include <xcb/xcb.h>
#include <xcb/xcb_atom.h>
#include <xcb/xcb_ewmh.h>
#include <xcb/xcb_icccm.h>
#include <glib.h>
#include "xcb-internal.h"
#include "xcb.h"
#include "helper.h"
#include "modes/window.h"
#include "rofi.h"
#include "settings.h"
#include "widgets/textbox.h"
#include "timings.h"
#include "mode-private.h"
#include "rofi-icon-fetcher.h"
#define WINLIST 32
#define CLIENTSTATE 10
#define CLIENTWINDOWTYPE 10
// Fields to match in window mode
typedef struct {
char *field_name;
gboolean enabled;
} WinModeField;
typedef enum {
WIN_MATCH_FIELD_TITLE,
WIN_MATCH_FIELD_CLASS,
WIN_MATCH_FIELD_ROLE,
WIN_MATCH_FIELD_NAME,
WIN_MATCH_FIELD_DESKTOP,
WIN_MATCH_NUM_FIELDS,
} WinModeMatchingFields;
static WinModeField matching_window_fields[WIN_MATCH_NUM_FIELDS] = {
{
.field_name = "title",
.enabled = TRUE,
},
{
.field_name = "class",
.enabled = TRUE,
},
{
.field_name = "role",
.enabled = TRUE,
},
{
.field_name = "name",
.enabled = TRUE,
},
{
.field_name = "desktop",
.enabled = TRUE,
}};
static gboolean window_matching_fields_parsed = FALSE;
// a manageable window
typedef struct {
xcb_window_t window;
xcb_get_window_attributes_reply_t xattr;
char *title;
char *class;
char *name;
char *role;
int states;
xcb_atom_t state[CLIENTSTATE];
int window_types;
xcb_atom_t window_type[CLIENTWINDOWTYPE];
int active;
int demands;
long hint_flags;
uint32_t wmdesktop;
char *wmdesktopstr;
unsigned int wmdesktopstr_len;
cairo_surface_t *icon;
gboolean icon_checked;
uint32_t icon_fetch_uid;
uint32_t icon_fetch_size;
gboolean thumbnail_checked;
gboolean icon_theme_checked;
} client;
// window lists
typedef struct {
xcb_window_t *array;
client **data;
int len;
} winlist;
typedef struct {
unsigned int id;
winlist *ids;
// Current window.
unsigned int index;
char *cache;
unsigned int wmdn_len;
unsigned int clf_len;
unsigned int