/*
* rofi
*
* MIT/X11 License
* Copyright © 2013-2023 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.DMenu"
#include "config.h"
#include "helper.h"
#include "modes/dmenu.h"
#include "rofi-icon-fetcher.h"
#include "rofi.h"
#include "settings.h"
#include "view.h"
#include "widgets/textbox.h"
#include "xrmoptions.h"
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
#include <gio/gio.h>
#include <gio/gunixinputstream.h>
#include <glib-unix.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include "modes/dmenuscriptshared.h"
static int dmenu_mode_init(Mode *sw);
static int dmenu_token_match(const Mode *sw, rofi_int_matcher **tokens,
unsigned int index);
static cairo_surface_t *
dmenu_get_icon(const Mode *sw, unsigned int selected_line, unsigned int height);
static char *dmenu_get_message(const Mode *sw);
static inline unsigned int bitget(uint32_t const *const array,
unsigned int index) {
uint32_t bit = index % 32;
uint32_t val = array[index / 32];
return (val >> bit) & 1;
}
static inline void bittoggle(uint32_t *const array, unsigned int index) {
uint32_t bit = index % 32;
uint32_t *v = &array[index / 32];
*v ^= 1 << bit;
}
typedef struct {
/** Settings */
// Separator.
char separator;
unsigned int selected_line;
char *message;
char *format;
struct rofi_range_pair *urgent_list;
unsigned int num_urgent_list;
struct rofi_range_pair *active_list;
unsigned int num_active_list;
uint32_t *selected_list;
unsigned int num_selected_list;
unsigned int do_markup;
// List with entries.
DmenuScriptEntry *cmd_list;
unsigned int cmd_list_real_length;
unsigned int cmd_list_length;
unsigned int only_selected;
unsigned int selected_count;
gchar **columns;
gchar *column_separator;
gboolean multi_select;
GThread *reading_thread;
GAsyncQueue *async_queue;
gboolean async;
FILE *fd_file;
int fd;
int pipefd[2];
int pipefd2[2];
guint wake_source;
gboolean loading;
char *ballot_selected;
char *ballot_unselected;
} DmenuModePrivateData;
/** Maximum number of lines rofi parses async before it pushes it to the main
* thread. */
#define BLOCK_LINES_SIZE 2048
typedef struct {
unsigned int length;
DmenuScriptEntry values[BLOCK_LINES_SIZE];
DmenuModePrivateData *pd;
} Block;
static void read_add_block(DmenuModePrivateData *pd, Block **block, char *data,
gsize len) {
if ((*block) == NULL) {
(*block) = g_malloc0(sizeof(Block));
(*block<